tags:

views:

45

answers:

2

Hi,

I have the following SOAP message that i want to post it to my WCF Service and get response.

"<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"&gt;\r\n  <s:Header>\r\n    <a:Action s:mustUnderstand=\"1\">http://schemas.devleap.com/OrderService/IOrderService/InsertOrder&lt;/a:Action&gt;\r\n    <a:MessageID>urn:uuid:4cb619b7-365b-4108-880f-b302029d03c2</a:MessageID>\r\n    <a:ReplyTo>\r\n      <a:Address>http://www.w3.org/2005/08/addressing/anonymous&lt;/a:Address&gt;\r\n    </a:ReplyTo>\r\n  </s:Header>\r\n  <s:Body>\r\n    <InsertOrder xmlns=\"http://schemas.devleap.com/OrderService\"&gt;\r\n      <order xmlns:d4p1=\"http://schemas.devleap.com/OrderService/Order\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"&gt;\r\n        <d4p1:IdCustomer>2</d4p1:IdCustomer>\r\n        <d4p1:IdOrder>46</d4p1:IdOrder>\r\n        <d4p1:OrderItems xmlns:d5p1=\"http://schemas.devleap.com/OrderService/OrderItems\" xmlns:d5p2=\"http://schemas.devleap.com/OrderService/OrderItem\"&gt;\r\n          <d5p1:OrderItem>\r\n            <d5p2:IdProduct>P01</d5p2:IdProduct>\r\n            <d5p2:Quantity>5</d5p2:Quantity>\r\n            <d5p2:EuroPrice>20</d5p2:EuroPrice>\r\n          </d5p1:OrderItem>\r\n          <d5p1:OrderItem>\r\n            <d5p2:IdProduct>P01</d5p2:IdProduct>\r\n            <d5p2:Quantity>5</d5p2:Quantity>\r\n            <d5p2:EuroPrice>20</d5p2:EuroPrice>\r\n          </d5p1:OrderItem>\r\n        </d4p1:OrderItems>\r\n      </order>\r\n    </InsertOrder>\r\n  </s:Body>\r\n</s:Envelope>"

How can i post this SOAP to the WCF service? I tried this but i get "The remote server returned an error: (500) Internal Server Error." exception.

        using (var client = new WebClient())
        {

            client.Headers.Add("Content-Type", "application/soap+xml; charset=utf-8");


            var response = client.UploadString("http://localhost:8000/OrderService", data);

        }

If i remove the header from Envelope and add:

client.Headers.Add("Content-Type", "application/soap+xml; charset=utf-8");
client.Headers.Add("SOAPAction", "\"http://schemas.devleap.com/OrderService/IOrderService/InsertOrder\"");

i get the same error.

If i put

client.Headers.Add("Content-Type", "text/xml; charset=utf-8");

i get exception that server expects "application/soap+xml; charset=utf-8".

If someone knows how to call it right please help.

Thank you, Adrya

A: 
  1. Create a SOAP client side proxy for the WCF Service by using Add Service Reference in Visual Studio (by specifying the service's URL)

  2. Instantiate that client proxy class

  3. Call the appropriate method on the client proxy to send the SOAP message to your serviec

marc_s
I can't do that from my application, because at runtime i need to invoke multiple WS and all i have is the WSDL + SOAP request, so I need to send the SOAP message directly.
Adrya
A: 

After more digging i managed to post the SOAP to the service. Here is code:

        WebClient myWebClient = new WebClient();
        myWebClient.Headers.Add("Content-Type", "application/soap+xml; charset=utf-8");
        byte[] byteArray = Encoding.ASCII.GetBytes(postData);
        byte[] responseArray = myWebClient.UploadData("http://localhost:8000/OrderService", "POST", byteArray);
        Console.WriteLine("\nResponse received was {0}", Encoding.ASCII.GetString(responseArray));
        Console.ReadKey();
Adrya
-1: you have solved the wrong problem. You should have followed the suggestion from marc_s. You could have switched between services simply by choosing the URL of the service.
John Saunders
I solved my problem. I can't do it "normal way" because everything happens at runtime. At runtime i don't know the services, i don't have their proxy classes, all i have is the URL and SOAP request.
Adrya