3

几天来,我一直在试图弄清楚为什么我的绑定中出现内容类型不匹配错误。有无数其他人似乎遇到了这个问题,但所有的解决方案都不适用或没有奏效。

我到处寻找,试图弄清楚为什么会出现以下错误:

“/”应用程序中的服务器错误。

内容类型application/soap+xml;响应消息的 charset=utf-8 与绑定的内容类型不匹配 (text/xml; charset=utf-8)。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 823 个字节是:

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><GetQuoteResponse xmlns="http://soap.service.GMO.com"><Quote_Response><errorMessage></errorMessage><return_List><item><errorMessage></errorMessage><monthlyPremiumAmount>6.0</monthlyPremiumAmount><webID>7P3W4Txst</webID><basePer1>1000.0</basePer1><basePer2>0.0</basePer2><baseRate1>0.05</baseRate1><baseRate2>0.0</baseRate2><benefitID>5365</benefitID><coverageAmount>100000</coverageAmount><grossPer1>1000.0</grossPer1><grossPer2>0.0</grossPer2><grossRate1>0.06</grossRate1><grossRate2>0.0</grossRate2></item></return_List></Quote_Response></GetQuoteResponse></soapenv:Body></soapenv:Envelope>.

我正在使用的 Web 服务未托管在 IIS 中。Web 服务本身似乎工作正常,因为我们使用 SoapUI 并将所有正确的结果返回给我们。您还可以从上面的错误消息中看到,正在从 Web 服务返回值。

我也一直在使用 Fiddler,并且能够确认请求标头内容类型是 text/xml,响应标头内容类型是 application/soap+xml。

我们有一个服务引用所在的数据层。app.config 如下所示:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="IMSQuoteServiceBinding" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default"  />
                </security>

            </binding>

        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://hostingServerName:81/cgi-bin/jsmdirect?IMSQuote"
            binding="basicHttpBinding" bindingConfiguration="IMSQuoteServiceBinding"
            contract="Quote.IMSQuoteServicePortType" name="IMSQuoteServicePort" />
    </client>
</system.serviceModel>

网站 web.config 如下所示:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="IMSQuoteServiceBinding" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>

    </binding>
  </basicHttpBinding>    

</bindings>
<client>
  <endpoint address="http://hostingServerName:81/cgi-bin/jsmdirect?IMSQuote"
      binding="basicHttpBinding" bindingConfiguration="IMSQuoteServiceBinding"
      contract="Quote.IMSQuoteServicePortType" name="IMSQuoteServicePort" />
</client>

任何帮助将不胜感激。我对 WCF 有点陌生,对任何和所有想法都持开放态度。

预先感谢大家的帮助。如果您需要我提供更多信息,请告诉我。

4

1 回答 1

4

Just as an update.

I changed the service binding from basicHttpBinding to wsHttpBinding. Changing the binding to wsHttpBinding changed the SOAP service to send as a SOAP 1.2 call rather than a SOAP 1.1 call. Once I did this, the content types matched on the send and receive calls which resolved the binding mismatch error.

于 2012-12-18T17:00:43.000 回答