title: Direct POST to WCF WSDL-first web service
body: <p>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!</p>
  
  <p>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.</p>
  
  <p>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!</p>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>&lt;MessageLogTraceRecord&gt;&lt;![CDATA[&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;s:Header&gt;
  &lt;To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://localhost:57567/Service1.svc&lt;/To&gt;
  &lt;Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://www.nowhere.co.uk/RequestService/RequestOperation&lt;/Action&gt;
  &lt;/s:Header&gt;
  &lt;/s:Envelope&gt;
  ]]&gt;&lt;/MessageLogTraceRecord&gt;
  </code></pre>
  
  <p>Whereas the WCF messages appear as:</p>
  
  <pre><code>&lt;MessageLogTraceRecord&gt;
  &lt;HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace"&gt;
  &lt;Method&gt;POST&lt;/Method&gt;
  &lt;QueryString&gt;&lt;/QueryString&gt;
  &lt;WebHeaders&gt;
  &lt;Connection&gt;Keep-Alive&lt;/Connection&gt;
  &lt;Content-Length&gt;185&lt;/Content-Length&gt;
  &lt;Content-Type&gt;text/xml; charset=utf-8&lt;/Content-Type&gt;
  &lt;Accept-Encoding&gt;gzip, deflate&lt;/Accept-Encoding&gt;
  &lt;Expect&gt;100-continue&lt;/Expect&gt;
  &lt;Host&gt;localhost:57567&lt;/Host&gt;
  &lt;VsDebuggerCausalityData&gt;uIDPo4VLDcJD5AZDjB5sdmoeakEAAAAAH/hWABuWQ0iiq47QDHh0GlelCLcEx7FLibxRvpq1tTgACQAA&lt;/VsDebuggerCausalityData&gt;
  &lt;SOAPAction&gt;"http://www.nowhere.co.uk/RequestService/RequestOperation"&lt;/SOAPAction&gt;
  &lt;/WebHeaders&gt;
  &lt;/HttpRequest&gt;
  &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;s:Header&gt;
  &lt;To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://localhost:57567/Service1.svc&lt;/To&gt;
  &lt;Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://www.nowhere.co.uk/RequestService/RequestOperation&lt;/Action&gt;
  &lt;/s:Header&gt;
  &lt;/s:Envelope&gt;
  &lt;/MessageLogTraceRecord&gt;
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;s:Header&gt;
  &lt;To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://localhost:57567/Service1.svc&lt;/To&gt;
  &lt;Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://www.nowhere.co.uk/RequestService/RequestOperation&lt;/Action&gt;
  &lt;/s:Header&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>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..</p>
  
  <p>Can anyone offer any help on this rather frustrating problem?</p>
  
  <p>Thanks in advance</p>