简体   繁体   中英

Ajax: The content type text\/html of the response message does not match the content type of the binding (application\/soap+xml; charset=utf-8)

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.

阿贾克斯电话

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

世界足球联合会

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!!

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM