简体   繁体   English

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

[英]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. 我已经阅读了几个小时的帖子,内容涉及“响应消息的内容类型text / html与绑定的内容类型不匹配(application / soap + xml; charset = utf-8)”问题,但似乎都不存在解决我的问题。

Let me explain: 让我解释:

I have an ajax call to a WCF method which returns a json object. 我对WCF方法进行了ajax调用,该方法返回了一个json对象。

阿贾克斯电话

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. 这是应用程序具有的唯一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>

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. 因此,我的ajax调用了我在同一应用程序中托管的svc,在Visual Studio 2010环境中可以正常工作,但是当我尝试在IIS上对其进行调试时,这就是达到WCF方法后得到的结果。

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

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 我知道这一定是IIS绑定的一种情况,但我不知道在哪里看,因为我的服务器web.config与客户端web.config相同

I'm working in a Windows 7 Enterprise, IIS 7.5, VS2010 and jquery 1.6.2 我正在Windows 7企业版,IIS 7.5,VS2010和jquery 1.6.2中工作

Please help me!! 请帮我!!

You can delete the "jsonBehaviour" (as it's not used) and try putting this inside your "poxBehaviour": 您可以删除“ jsonBehaviour”(未使用),然后尝试将其放入“ 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 . 在您的AJAX请求中,您可以设置accept标头或内容类型以明确告诉服务器您想要JSON结果,否则它将使用默认格式, 请参见此处以获取有关“ automaticFormatSelectionEnabled”设置的更多详细信息

Note that this assumes your WCF attributes are set appropriately in your server code (which they probably are otherwise it would have never worked). 请注意,这假设您在服务器代码中正确设置了WCF属性(否则可能永远无法使用它们)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么是<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” /> ? - What is <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />? 尝试编辑文件时出现错误消息:“内容类型 (UTF-8) 中指定的字符集与文件内容不匹配。” - Error message when trying to edit a file : "The character set specified in the content type (UTF-8) does not match file content." <meta charset="utf-8">对比<meta http-equiv="Content-Type"> - <meta charset="utf-8"> vs <meta http-equiv="Content-Type"> Python:分割text / xml; charset = UTF-8 - Python: Splitting text/xml;charset=UTF-8 这是一个有效的SOAP响应内容类型吗? - Is this a valid SOAP response content-type? 数据库不采集英文以外的内容【Charset/Unicode设置为UTF-8】 - The database does not collect the content other than English [Charset/Unicode set to UTF-8] HTML内容类型元标记(utf8) - HTML Content type meta tag (utf8) MIME类型不匹配,但没有“charset = utf-8” <script> tag, error with “charset=utf-8” in <script> tag - MIME type mismatch without “charset=utf-8” in <script> tag, error with “charset=utf-8” in <script> tag android如何在响应中使用HttpURLConnection(Content-Type:text / html)? - How to use HttpURLConnection with Response (Content-Type: text/html ) in android? 我需要在 HTML 和 PHP 中声明内容类型/字符集吗? - Do I need to declare content type/charset in both HTML and PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM