Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've found the solution. Thanks to Fiddler, I was able to view more of the response I was getting back from the service. The error was </p> <blockquote> <p>The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding.</p> </blockquote> <p>Armed with this information I started looking into the WebContentTypeMapper. I found <a href="https://stackoverflow.com/questions/2038673/wcf-input-huge-xml-as-stream-with-content-type-xml-text">this</a> article useful, and after adding the WebContentTypeMapper method I was able to see that the contentType of my request coming from the XDomainRequest was of type "application/json" (as expected) when I did <strong>not</strong> include an argument in the XDomainRequest.send() method, but changed to type "application/octet-stream" when an argument was passed in. (ie. xdr.send(data)) I don't know why it changes to octet-stream, but in doing so it would cause the service method to throw a 500 error (with the message from above) and therefore cause the xdr request to error. But the WebContentTypeMapper is aptly named and using it to change the contentType is easy enough. After correcting it to type Json my xdr is working well.</p> <p>Here's the method:</p> <pre><code>public class CustomContentTypeMapper : WebContentTypeMapper { public override WebContentFormat GetMessageFormatForContentType(string contentType) { if (contentType == "application/octet-stream") { return WebContentFormat.Json; } else { return WebContentFormat.Default; } } } </code></pre> <p>And here are the portions of the config file that were updated:</p> <pre><code>&lt;endpoint address="AjaxEndpoint" behaviorConfiguration="AjaxBehaviour" contract="WcfService1.IService1" binding="customBinding" bindingConfiguration="CustomMapper"/&gt; ... &lt;bindings&gt; &lt;customBinding&gt; &lt;binding name="CustomMapper"&gt; &lt;webMessageEncoding webContentTypeMapperType="WcfService1.CustomContentTypeMapper, WcfService1" /&gt; &lt;httpTransport manualAddressing="true" /&gt; &lt;/binding&gt; &lt;/customBinding&gt; &lt;/bindings&gt; </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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