![](/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.