Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>one of main reasons why the original code didn't work was because any xml string data would need to be url encoded if being passed in the url path or query string.</p> <p>in my opinion, however, if you want the client to be sending you data as xml in to your service method, then it should <strong>not</strong> be done in the url. The url has an indeterminate maximum length, depending on the browser, the version of iis and also any web proxies that are sitting between the client on the server.</p> <p>this means sending the data in the body of the request, which means a verb other than GET. So let's use POST.</p> <p>declare the 'data' parameter as before on the method signature, but take the parameter out of the UriTemplate, and make it WebInvoke (default verb is POST as you know).</p> <pre><code>[WebInvoke(UriTemplate = "/method1", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)] string Method2(string data); </code></pre> <p>Then your POST body reques should be formatted as follows:</p> <pre><code>&lt;data&gt;&lt;![CDATA[data xml goes in here]]&gt;&lt;/data&gt; </code></pre> <p>Why the CDATA Section? Think about the target parameter type - string. You want to pass XML in that string. Therefore, you need to make sure that the WCF serializer doesn't think of the data as complex data that is to be read directly. The same would be true if your request format was JSON and you wanted to send a JSON string to the service.</p>
 

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