0

我需要在我的 c# 代码库中使用第三方服务,这需要将节点添加到请求中。(以编程方式跟进soap请求中的ws-addressing问题

到目前为止我能够实现的是

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header xmlns:soap="http://www.w3.org/2005/08/addressing">
      <wsa:Action xmlns:wsa="Action">http://tempuri.org/GetDetails</wsa:Action>
      <wsa:To xmlns:wsa="To">SAMPLEURL.svc/DP2Svcs11</wsa:To>
   </soap:Header>
   <soap:Body>
      <GetBookingDetails xmlns="http://tempuri.org/">
         <UserName>testt</UserName>
         <Password>testt</Password>

      </GetBookingDetails>
   </soap:Body>
</soap:Envelope>

我最终需要的是服务

 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
      <wsa:Action>http://tempuri.org/GetDetails</wsa:Action>
      <wsa:To>http://SAMPLEURL.svc/DP2Svcs11</wsa:To>
   </soap:Header>

   <soap:Body>
      <GetBookingDetails xmlns="http://tempuri.org/">
         <UserName>testt</UserName>
         <Password>test</Password>
      </GetBookingDetails>
   </soap:Body>
</soap:Envelope>

有人可以帮助如何更改提到的命名空间吗?

用于生成上述响应的代码是

XmlDocument xmlDoc = new XmlDocument();
        inwardStream.Position = 0;
        var streamReader = new StreamReader(inwardStream);
        var streamWriter = new StreamWriter(outwardStream);
        message = streamReader.ReadToEnd();

        xmlDoc.LoadXml(message);
        var insertNode = (((xmlDoc).LastChild));
        var headerNode = xmlDoc.CreateElement("soap", "Header", "http://www.w3.org/2005/08/addressing");

        //var actionNode = xmlDoc.CreateElement("wsa", "Action", "http://www.w3.org/2004/12/addressing");
        //var actionNodeTo = xmlDoc.CreateElement("wsa", "To", "http://www.w3.org/2004/12/addressing");
        var actionNode = xmlDoc.CreateElement("wsa:Action", "Action");
        var actionNodeTo = xmlDoc.CreateElement("wsa:To", "To");

        actionNode.InnerText = "http://tempuri.org/IFlightBookingService/GetBookingDetails";
        actionNodeTo.InnerText = "http://54.251.105.26/GQWCF_FlightEngine/FlightBookingService.svc/DP2Svcs11";

        headerNode.AppendChild(actionNode);
        headerNode.AppendChild(actionNodeTo);
        (((((xmlDoc))).LastChild)).InsertBefore(headerNode, (((((xmlDoc))).LastChild)).FirstChild);
4

1 回答 1

0

编辑行:

var actionNode = xmlDoc.CreateElement("wsa:Action", "Action");
        var actionNodeTo = xmlDoc.CreateElement("wsa:To", "To");

至:

var actionNode = xmlDoc.CreateElement("wsa:Action");
        var actionNodeTo = xmlDoc.CreateElement("wsa:To");
于 2013-11-11T10:34:15.510 回答