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/">
<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?
It sounds to me like you could create a sort of proxy application - change the URL in your client to point to the proxy - proxy would record the entire SOAP request message and send it on to the web service - receive the response, log it, and send it on to your client.
Normally, a WCF service will use SOAP, but if you build a REST service, clients will be accessing your service with a different architectural style (calls, serialization like JSON, etc.). Exposing a WCF service with both SOAP and REST endpoints, requires just a few updates to the codebase and configuration.
In ASP.NET Development services, SOAP messages are exchanged over HTTP, but WCF services can exchange the message using any format over any transport protocol. Though, SOAP is a default format that WCF uses. 10. WCF services have timeouts by default that can be configured.
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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With