tags:

views:

1052

answers:

2

I have a WCF service reference:

http://.../Service.svc(?WSDL)

and I have an XML file containing a compliant SOAP envelope

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  <soapenv:Body>
    <MyXML>
       ...

Now, I would like to send this raw data directly to the service (and receive the response) via some C# code without using a Visual Studio service reference.

Is this possible, and if so, how?

+1  A: 

You could try using the webclient class and posting your xml to the service.

Shiraz Bhaiji
+2  A: 

You could use UploadString. You need to set the Content-Type and SOAPAction headers appropriately:

class Program
{
    static void Main(string[] args)
    {
        using (var client = new WebClient())
        {
            // read the raw SOAP request message from a file
            var data = File.ReadAllText("request.xml");
            // the Content-Type needs to be set to XML
            client.Headers.Add("Content-Type", "text/xml;charset=utf-8");
            // The SOAPAction header indicates which method you would like to invoke
            // and could be seen in the WSDL: <soap:operation soapAction="..." /> element
            client.Headers.Add("SOAPAction", "\"http://www.example.com/services/ISomeOperationContract/GetContract\"");
            var response = client.UploadString("http://example.com/service.svc", data);
            Console.WriteLine(response);
        }
    }
}
Darin Dimitrov