Sending raw SOAP XML directly to WCF service from C#

后端 未结 3 654
陌清茗
陌清茗 2021-01-30 06:09

I have a WCF service reference:

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

and I have an XML file containing a compliant SOAP envelope



        
相关标签:
3条回答
  • 2021-01-30 06:13

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

    0 讨论(0)
  • 2021-01-30 06:15

    I just want to comment that Darin's response worked for me, except that I had to take out the extra quotes around the SOAPAction header value (substitute your uri, of course):

    client.Headers.Add("SOAPAction", "http://www.example.com/services/ISomeOperationContract/GetContract");
    
    0 讨论(0)
  • 2021-01-30 06:28

    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);
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题