开发者

Direct POST to WCF WSDL-first web service

I need some help posting some XML to a WCF service. In essence, the issue I am experiencing is a HTTP response of "400: Bad request" - as descriptive as that sounds, i'm struggling to find any answers!

First of all, the service I have built in WCF is based on an existing WSDL, originally from an IBM WebSphere web service. After some manipulation (removal of MIME attachments, downloading of some remote schemas) I managed to get svcutil to generate a service interface which for all intents and purposes seems valid.

I have implemented the interface in to my WCF service and when running the WCF test client, I can attach to the service, submit a request and receive a response no problems. So far so good!

When moving to a test application for posting XML to web services via the HttpWebRequest class I start receiving "400: Bad request" responses even though I am using the XML provided by the WCF test client.

I've used WCF tracing to dump out the messages it is receiving and there is one striking difference - all of the WCF test client messages are populating correctly and displaying their header information etc, all of the once from my SOAP test utility are showing as "Malformed". Looking in to the message tab, the manual POST messages I am sending have the body wrapped in a element:

<MessageLogTraceRecord><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:57567/Service1.svc</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.nowhere.co.uk/RequestService/RequestOperation</Action>
</s:Header>
</s:Envelope>
]]></MessageLogTraceRecord>

Whereas the WCF messages appear as:

<MessageLogTraceRecord>
<HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
<Method>POST</Method>
<QueryString></QueryString>
<WebHeaders>
<Connection>Keep-Alive</Connection>
<Content-Length>185</Content-Length>
<Content-Type>text/xml; charset=utf-8</Content-Type>
<Accept-Encoding>gzip, deflate</Accept-Encoding>
<Expect>100-continue</Expect>
<Host>localhost:57567</Host>
<VsDebuggerCausalityData>uIDPo4VLDcJD5AZDjB5sdmoeakEAAAAAH/hWABuWQ0iiq47QDHh0GlelCLcEx7FLibxRvpq1tTgACQAA</VsDebuggerCausalityData>
<SOAPAction>"http://www.nowhere.co.uk/RequestService/RequestOperation"</SOAPAction>
</WebHeaders>
</HttpRequest>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:57567/Service1.svc</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.nowhere.co.uk/RequestService/RequestOperation</Action>
&开发者_StackOverflowlt;/s:Header>
</s:Envelope>
</MessageLogTraceRecord>

I've tried tracing in Fiddler to no avail - I can't get the WCF test client to submit requests through the proxy it creates despite modifying it's app.config file. I have traced my SOAP request however can can see the following:

Content-Type: text/xml; charset="utf-8"
Accept-Encoding: gzip, deflate
Host: 127.0.0.1:57567
SOAPAction: "http://www.nowhere.co.uk/RequestService/RequestOperation"
Content-Length: 459
Expect: 100-continue
Connection: Keep-Alive

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:57567/Service1.svc</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.nowhere.co.uk/RequestService/RequestOperation</Action>
</s:Header>
</s:Envelope>

As far as I can tell, the message I am sending should be ok - outside of the headers and the message content I can't see what else could be sent.

Last thing I should say is that I am by no means a WCF expert and I have had to change the specific SOAPAction value due to commercial sensitivity..

Can anyone offer any help on this rather frustrating problem?

Thanks in advance


Thanks for the Fiddler comment - I managed to get the WCF request traced and using the xml from the request seems to work! I've since tried a full message which works against the WebSphere service against the WCF client and that works too!

I think the issue was the Action header. I believe WCF only support a couple of revisions of WSA, none of which are the one this particular WSDL was using. Looking at the original requests that were failing (pulled out of the WCF Test Client front end) the addressing namespace it was using was declared as:

xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"

Whereas the actual WCF request that goes across to the service is declared as:

xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"

The actual element itself was populated with the same value, just the difference in namespace:

<wsa:Action>http://www.nowhere.co.uk/RequestService/RequestOperation</wsa:Action>

So using the correct addressing version and omitting the newer, WCF compatible version appears to have fixed the problem!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜