Reputation: 6723
I'm trying to call a SOAP-based WCF web service by creating an HTTP request by hand. I need to do this because I'm trying to implement this in an environment that will have HTTP access, but not the WCF service client stuff. It will actually be implemented in a different language, but I'm trying to do a proof of concept in C# first.
The WCF service has a simple function that takes a string address and then returns a complex object with geocoding information about the address. Right now, I'm just looking for it to return a proper response as a string. As it is, it returns HTML describing the WSDL discovery, so the call isn't working.
I pulled the SOAP message from an actual functioning service call (I wrote some code to intercept and extract the SOAP message before it went out).
So the trick now is just getting the rest of the HTTP to work. So my code is as follows:
string soap = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
" <s:Header>" +
" <Action s:mustUnderstand=\"1\" xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">http://tempuri.org/IGeoCode/GetLocation</Action>" +
" </s:Header>" +
" <s:Body>" +
" <GetLocation xmlns=\"http://tempuri.org/\">" +
" <address>1600 Pennsylvania Ave NW, Washington, DC 20500</address>" +
" </GetLocation>" +
" </s:Body>" +
" </s:Envelope>";
var obj = new XMLHTTP60();
obj.open("POST", @"http://MyServer:4444/GeoCode.svc");
obj.setRequestHeader("Content-Type", "text/xml");
obj.setRequestHeader("SOAPAction", "http://MyServer:4444/GeoCode.svc");
obj.setRequestHeader("Content-Length", soap.Length.ToString());
obj.send(soap);
string stat = obj.statusText;
string str = obj.responseText;
string resp = obj.getAllResponseHeaders();
What I expect back is something along the lines of:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<GetLocationResponse xmlns="http://tempuri.org/">
<GetLocationResult xmlns:a="http://schemas.datacontract.org/2004/07/GeoCodeSvc" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
...
Lots of stuff here
...
</GetLocationResult>
</GetLocationResponse>
</s:Envelope>
</s:Body>
Instead, I'm getting a 400 (Bad Request) status.
Upvotes: 0
Views: 2073
Reputation: 201
I think your problem is with the SOAPAction statement. You don't want to point that to your service. Instead, it should be whatever the WSDL calls the end point.
If you're feeling adventurous, the end point is typically one of the last entries in the WSDL. I can't recall the specific term they use, but it should be obvious.
HTH, Jim
Upvotes: 1