0

I need to use a third party service in my c# codebase which requires node to be added into the request. (Follow up question to ws-addressing in soap request programatically)

What I am able to achieve till now is

    <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>

What I need finally to hit the service is

 <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>

Can someone please help how to change the namespaces as mentioned?

Code used to generate above response is

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);
Community
  • 1
  • 1
Hitesh
  • 147
  • 2
  • 16

1 Answers1

0

Edit lines:

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

to:

var actionNode = xmlDoc.CreateElement("wsa:Action");
        var actionNodeTo = xmlDoc.CreateElement("wsa:To");
Lucky Lefty
  • 347
  • 1
  • 8
  • Lucky, Changing to what you suggested will result into and nodes instead of and node. – Hitesh Nov 11 '13 at 11:46
  • sorry c/p I meant var actionNode = xmlDoc.CreateElement("wsa:Action"); var actionNodeTo = xmlDoc.CreateElement("wsa:To"); – Lucky Lefty Nov 12 '13 at 07:59