Ajax:响应消息的内容类型text \ / html与绑定的内容类型不匹配(application \ / soap + xml; charset = utf-8)

时间:2013-04-04 01:04:38

标签: html xml ajax wcf iis

我已经阅读了几个小时与“回复消息的内容类型text / html与绑定的内容类型(application / soap + xml; charset = utf-8)”相关的帖子 但是他们似乎没有解决我的问题。

让我解释一下:

我对WCF方法进行了ajax调用,该方法返回一个json对象。

Ajax Call

好吧,现在我的wcf服务位于同一个应用程序中(不要问我原因):

WCF

这是应用程序拥有的唯一web.config。

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

所以,我的ajax调用我在同一个应用程序中托管的svc,在Visual Studio 2010环境中工作正常,但是当我尝试在IIS上调试它时,这是我在到达WCF方法后得到的。

  

“Associate”:0,“MenuOptions”:“响应消息的内容类型text / html与绑定的内容类型不匹配(application / soap + xml; charset = utf-8)。如果使用自定义编码器,确保正确实现了IsContentTypeSupported方法。响应的前1024个字节是:...

我知道这必须是某种绑定o IIS的情况,但我不知道在哪里看,因为我的服务器web.config与客户端web.config相同

我在Windows 7企业版,IIS 7.5,VS2010和jquery 1.6.2

中工作

请帮助我!!

1 个答案:

答案 0 :(得分:0)

您可以删除“jsonBehaviour”(因为它没有使用)并尝试将其放入“poxBehaviour”中:

<webHttp automaticFormatSelectionEnabled ="true" />

您还应该能够简化服务并使用以下内容:

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

在您的AJAX请求中,您可以设置accept标头或content-type以明确告诉服务器您想要JSON结果,否则它将使用默认格式see here for more details on the "automaticFormatSelectionEnabled" setting

请注意,这假设您的WCF属性在您的服务器代码中正确设置(否则它们可能从未使用过)。

相关问题