内容类型text / html; charset =响应消息的UTF-8与绑定的内容类型不匹配(text / xml; charset = utf-8)

时间:2011-03-10 17:05:40

标签: c# wcf web-services

我使用独立应用程序创建了WCF服务并测试了WCF客户端。我能够使用Internet Explorer查看此服务,也可以在Visual Studio服务引用中查看。这是错误消息。

"The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)."

请问您可能会出现什么问题?

谢谢。

5 个答案:

答案 0 :(得分:17)

由于返回的内容类型为text/html,我怀疑您的调用会导致WCF之外的服务器端错误(您收到的是HTML错误页面)。

尝试使用Fiddler等网络调试代理查看响应。


(根据评论编辑):

根据您的评论,我发现您的WCF托管在Sharepoint 2010下,位于经过格式验证的网站中。

您收到的错误是由于您的WCF客户端未使用sharepoint进行身份验证 - 它没有有效的身份验证Cookie。然后Sharepoint将HTTP重定向返回到html页面(login.aspx页面);这是您的WCF客户端不期望的。

为了更进一步,您必须从Sharepoint获取身份验证cookie(请参阅Authentication Web Service)并将其传递给您的WCF客户端。


(更新编辑):

错误:该网站正在使用基于声明的身份验证。

虽然这不一定是由于cookie或表单身份验证,但提供的错误消息的解释保持不变。身份验证问题会导致重定向到HTML页面,而WCF客户端无法处理该页面。

答案 1 :(得分:2)

这可能会有所帮助,请检查IIS 7中的网址重写规则。如果您没有正确配置规则,则会出现此问题。

答案 2 :(得分:0)

听起来您的应用程序期望XML但是接收纯文本。你传入的是什么类型的物体?

答案 3 :(得分:0)

text / html是SOAP 1.1标头,Content-Type:application / soap + xml是SOAP 1.2 验证绑定并返回标头。 它应该是相同的1.1或1.2

答案 4 :(得分:0)

将以下代码添加到web.config服务器项目

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="basicHttpBinding_IService">
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

<services>
  <service name="Service">
    <endpoint address="" name="BasicHttpBinding_IService"
              binding="basicHttpBinding"
              bindingConfiguration="basicHttpBinding_IService"
              contract="IService" />
  </service>

然后更新客户端Web服务,更新后,进行以下更改web.config

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService">
      <security mode="Transport" />
    </binding>
  </basicHttpBinding>
</bindings>


  <endpoint address="https://www.mywebsite.com/Service.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
    contract="Service.IService" name="BasicHttpBinding_IService" />

我希望有用

相关问题