![](/img/trans.png)
[英]What is <meta http-equiv=“Content-Type” content=“text/html; 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)
我已经阅读了几个小时的帖子,内容涉及“响应消息的内容类型text / html与绑定的内容类型不匹配(application / soap + xml; charset = utf-8)”问题,但似乎都不存在解决我的问题。
让我解释:
我对WCF方法进行了ajax调用,该方法返回了一个json对象。
好的,现在我的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个字节为:...
我知道这一定是IIS绑定的一种情况,但我不知道在哪里看,因为我的服务器web.config与客户端web.config相同
我正在Windows 7企业版,IIS 7.5,VS2010和jquery 1.6.2中工作
请帮我!!
您可以删除“ jsonBehaviour”(未使用),然后尝试将其放入“ poxBehaviour”中:
<webHttp automaticFormatSelectionEnabled ="true" />
您还应该能够简化服务,只需使用以下内容:
<endpoint address="pox" behaviorConfiguration="poxBehavior" kind="webHttpEndpoint" contract="HSMobileApp.Services.IHSMobile" />
在您的AJAX请求中,您可以设置accept标头或内容类型以明确告诉服务器您想要JSON结果,否则它将使用默认格式, 请参见此处以获取有关“ automaticFormatSelectionEnabled”设置的更多详细信息 。
请注意,这假设您在服务器代码中正确设置了WCF属性(否则可能永远无法使用它们)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.