0
votes

I've been reading for hours posts related with "The content type text/html of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8)" issue But non of them seem to solve my problem.

Let me explain:

I have an ajax call to a WCF method which returns a json object.

Ajax Call

ok now my wcf service is located in the same app (don't ask me why):

WCF

this is the unique web.config that the app has.

<services>
    <service behaviorConfiguration="defaultBehavior" name="HSMobileApp.Services.HSMobile">

        <endpoint address="pox" behaviorConfiguration="poxBehavior" binding="webHttpBinding" bindingConfiguration="webBinding" contract="HSMobileApp.Services.IHSMobile" />

    <host>
        <baseAddresses>
            <add baseAddress="/Services/HSMobile" />
        </baseAddresses>
    </host>
    </service>
</services>

<bindings>
  <webHttpBinding>
    <binding name="webBinding" />
  </webHttpBinding>
</bindings>

<behaviors>
  <endpointBehaviors>
    <behavior name="poxBehavior">
      <webHttp defaultOutgoingResponseFormat="Xml" />
    </behavior>
    <behavior name="jsonBehavior">
        <webHttp defaultOutgoingResponseFormat="Json" />
    </behavior>
  </endpointBehaviors>

  <serviceBehaviors>
    <behavior name="defaultBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

So, my ajax calls the svc that I'm hosting in the same application, In the Visual Studio 2010 environment works fine, but when I try to debug it on the IIS this is what I got after reaching the WCF method.

"Associate":0,"MenuOptions":"The content type text/html of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were:...

I know this must be somekind of binding o IIS situation but I don't know where to look at, because my server web.config is the same that the client web.config

I'm working in a Windows 7 Enterprise, IIS 7.5, VS2010 and jquery 1.6.2

Please help me!!

1
In your web.config you never actually use the 'jsonBehaviour' for anything, so the 'pox' endpoint always assumes XML. Your client machine.config might be doing something with the "automaticFormatSelectionEnabled" setting and/or default endpoint which allow it to change the output type depending on the request details.TheManWithNoName
Sorry, jsonBehaviour was a test that I left. My mstkLug

1 Answers

0
votes

You can delete the "jsonBehaviour" (as it's not used) and try putting this inside your "poxBehaviour":

<webHttp automaticFormatSelectionEnabled ="true" />

You should also be able to simplify your service and just use the following:

<endpoint address="pox" behaviorConfiguration="poxBehavior" kind="webHttpEndpoint" contract="HSMobileApp.Services.IHSMobile" />

In your AJAX request you can set the accept header or content-type to explicitly tell the server you want a JSON result otherwise it will use to the default format, see here for more details on the "automaticFormatSelectionEnabled" setting.

Note that this assumes your WCF attributes are set appropriately in your server code (which they probably are otherwise it would have never worked).