Note that there are some explanatory texts on larger screens.

plurals
  1. PO400 bad request sending xml payload to WCF REST service
    primarykey
    data
    text
    <p>I know there are a few posts asking about the 400 error, and I believe I've read all of them, but I think the problem I'm facing is different.</p> <p><strong>This is my WCF service contract</strong></p> <pre><code>[WebInvoke(UriTemplate = "/cust_key/{key}/prod_id/{id}", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)] Stream GetData(string key, string id, string data); </code></pre> <p><strong>And this is the code that I use to send the request to my rest svc</strong></p> <pre><code>request.RequestUri = new Uri("http://localhost:3138/v1/cust_key/company1/prod_id/testProductID"); request.ContentType = "application/xml"; request.HttpMethod = "POST"; string xml = @"&lt;Product&gt;&lt;name&gt;dell 400&lt;/name&gt;&lt;price&gt;400 dollars&lt;/price&gt;&lt;/Product&gt;"; byte[] message = Encoding.ASCII.GetBytes(xml); string data = Convert.ToBase64String(message); response = request.MakeWebRequest(null, data); </code></pre> <p>This gave me 400 bad request error. I've tried to change the xml string to the following two and they also produce 400 error</p> <pre><code>&lt;string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt; &lt;![CDATA[&lt;Product&gt;&lt;name&gt;dell 400&lt;/name&gt;&lt;price&gt;400 dollars&lt;/price&gt;&lt;/Product&gt;]]&gt; &lt;/string&gt; </code></pre> <p>or</p> <pre><code>&lt;![CDATA[&lt;Product&gt;&lt;name&gt;dell 400&lt;/name&gt;&lt;price&gt;400 dollars&lt;/price&gt;&lt;/Product&gt;]]&gt; </code></pre> <p>If the payload xml is empty string, then everything is fine and 200 is returned. Can anyone give me a hand?</p> <p><strong>Edit:</strong> my web.config section. it comes out of box from the <a href="http://visualstudiogallery.msdn.microsoft.com/fbc7e5c1-a0d2-41bd-9d7b-e54c845394cd" rel="nofollow">WCF REST Service Template 40(CS)</a></p> <pre><code>&lt;system.serviceModel&gt; &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"/&gt; &lt;standardEndpoints&gt; &lt;webHttpEndpoint&gt; &lt;!-- Configure the WCF REST service base address via the global.asax.cs file and the default endpoint via the attributes on the &lt;standardEndpoint&gt; element below --&gt; &lt;standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/&gt; &lt;/webHttpEndpoint&gt; &lt;/standardEndpoints&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload