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

The content type is text/html; charset=utf-8 of the response message does not match the content type of the association (text/xml; charset=utf-8)

提问人:h.z. 提问时间:3/26/2023 最后编辑:Lex Lih.z. 更新时间:3/28/2023 访问量:907

问:

我在 IIS 和 Visual Studio - asp 项目中使用, 我收到此错误:

System.ServiceModel.ProtocolException HResult=0x80131501 Message=内容类型为 text/html;响应消息的 charset=utf-8 与关联的内容类型 (text/xml; charset=utf-8) 不匹配。如果使用的是自定义编码器,请确保正确实现 IsContentTypeSupported 服务操作。响应的前 1024 个字节是:...

这是我的web.config:

<basicHttpBinding>
  <binding name="BasicHttpBinding_ICRMAppsDataProvider"  maxReceivedMessageSize="2147483646" />
      <binding name="DataServiceSoap" />
      <binding name="BasicHttpBinding_IService1" closeTimeout="00:05:00" 
               openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:25:00"
               allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="2147483646"
               maxReceivedMessageSize="2147483646" useDefaultWebProxy="true" textEncoding="utf-8">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
  </binding>
</basicHttpBinding>

和这个服务器 web.config:

  <services>
  <service behaviorConfiguration="ManagementServiceBehaviour" name="AService.Service1">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" contract="AService.IService1" />
  </service>
  <service behaviorConfiguration="webHttpBehavior" name="AService.RestfulService">
    <endpoint address="" behaviorConfiguration="webHttpBehavior" binding="webHttpBinding" bindingConfiguration="webBindingHttp" name="webBinding" bindingName="webBindingHttp" contract="AService.IRestfulService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="basicHttpBinding" maxReceivedMessageSize="2147483647" closeTimeout="00:25:00" openTimeout="00:25:00"   receiveTimeout="00:25:00" sendTimeout="00:25:00" textEncoding="utf-8">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" realm="" />
        <message clientCredentialType="UserName" />
      </security>
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="webBindingHttp" closeTimeout="00:25:00" openTimeout="00:25:00"   receiveTimeout="00:25:00" sendTimeout="00:25:00">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" realm="" />
       
      </security>
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

    </binding>
  </webHttpBinding>
</bindings>

我的错误是什么???

C# WCF UTF-8

评论


答:

0赞 Jiayao 3/27/2023 #1

通常,此错误意味着您的主机返回了错误页面。

因此,您可以尝试在 wcf 中使用跟踪来查找真正的问题,方法是:

  1. 右键单击 web.config,然后单击“编辑 WCF 配置”。

  2. 在“诊断”部分下,启用“日志自动刷新”、“消息日志记录”和“跟踪”,当然还要指定主机标识有权写入的路径。

  3. 执行该服务调用后检查跟踪文件,并找出真正的问题所在。

0赞 h.z. 3/28/2023 #2

我找到了答案: IIS 中池的属性“启用 32 位应用程序”为 TRUE,因此需要能够为 FALSE。

setting of pool application: