响应消息的WCF charset = utf-8与绑定的内容类型不匹配(application/soap + xml; charset = utf-8) [英] WCF charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8)

查看:133
本文介绍了响应消息的WCF charset = utf-8与绑定的内容类型不匹配(application/soap + xml; charset = utf-8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.NET 4.0在IIS 7.5中托管WCF服务.我还有一个WPF应用程序,该应用程序是使用Visual Studio 2010和.NET 4.0构建的客户端.我添加了服务引用,当我尝试调用函数时,出现以下异常

I'm hosting a WCF service in IIS 7.5 using .NET 4.0. I also have a WPF application that I am using as my client that was built with Visual Studio 2010 and .NET 4.0. I added my service reference and when I attempt to call a function, I get the following exception

内容类型为application/xml;响应消息的charset = utf-8与绑定的内容类型不匹配(application/soap + xml; charset = utf-8)

The content type application/xml; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8)

我能够在Web浏览器中导航到该服务,并且客户端和服务之间的绑定似乎是相同的(WsHttp绑定).

I am able to navigate to the service in a web browser and my bindings appear to be the same between the client and service (WsHttp bindings).

我知道有很多关于此错误的google结果,但似乎都与我的问题无关/对我的特定问题没有帮助.我尝试安装非HTTP激活功能以及其他各种小技巧.有人可以帮忙吗?谢谢

I know there are alot of google results about this error but none of them seemed to be relevant/help my specific problem. I tried installing Non-HTTP Activation features as well as a wide variety of other small tricks. Anybody be able to help? Thanks

编辑,这是我的配置(它们很长)

edit, here are my configs (they are quite lengthy)

客户

<?xml version="1.0"?>
<configuration>
   <system.serviceModel>
      <bindings>
         <basicHttpBinding>
             <binding name="ContentSoap" 
                 closeTimeout="00:01:00" openTimeout="00:01:00"
                 receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
                 maxBufferSize="2147483647" maxBufferPoolSize="2147483647" 
                 maxReceivedMessageSize="2147483647"
                 messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                 useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" 
                              maxArrayLength="2147483647"
                              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                               realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
             </binding>
             <binding name="OrderSoap" 
                 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>
        <netTcpBinding>
           <binding name="NetTcpBindingEndpoint" closeTimeout="00:01:00"
               openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
               transactionFlow="false" transferMode="Buffered"  
               transactionProtocol="OleTransactions"
               hostNameComparisonMode="StrongWildcard" listenBacklog="10"  
               maxBufferPoolSize="2147000000" maxBufferSize="65536" maxConnections="10" 
               maxReceivedMessageSize="2147000000">
              <readerQuotas maxDepth="32" maxStringContentLength="8192"  
                   maxArrayLength="2147000000" maxBytesPerRead="4096" 
                   maxNameTableCharCount="16384" />
              <reliableSession ordered="true" inactivityTimeout="00:01:00"
                               enabled="true" />
              <security mode="None">
                 <transport clientCredentialType="Windows" 
                            protectionLevel="EncryptAndSign" />
                 <message clientCredentialType="Windows" />
              </security>
           </binding>
       </netTcpBinding>
       <wsHttpBinding>
            <binding name="WSHttpBinding_IInmateCanteenServiceWeb" 
                 closeTimeout="00:01:00" openTimeout="00:01:00" 
                 receiveTimeout="00:10:00" sendTimeout="00:01:00"
                 bypassProxyOnLocal="false" transactionFlow="false"  
                 hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
                 messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
                 allowCookies="false">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" 
                   maxArrayLength="16384" maxBytesPerRead="4096" 
                   maxNameTableCharCount="16384" />
              <reliableSession ordered="true" inactivityTimeout="00:10:00"
                   enabled="false" />
              <security mode="Transport">
                  <transport clientCredentialType="None" proxyCredentialType="None"
                             realm="" />
              </security>
          </binding>
      </wsHttpBinding>
   </bindings>
   <client>
       <endpoint name="ContentSoap"
           address="http://media.team.twvending.net/storeservices/content.asmx"
           binding="basicHttpBinding" bindingConfiguration="ContentSoap"
           contract="MediaPortContent.ContentSoap"  />
       <endpoint name="OrderSoap"
           address="http://media.team.twvending.net/storeservices/order.asmx"
           binding="basicHttpBinding" bindingConfiguration="OrderSoap"
           contract="MediaPortOrder.OrderSoap"  />
       <endpoint name="NetTcpBindingEndpoint" 
           address="..."
           binding="netTcpBinding" bindingConfiguration="NetTcpBindingEndpoint"
           contract="WebCallBack.ICallbackService" />
       <endpoint name="WSHttpBinding_IInmateCanteenServiceWeb" 
           address="..."
           binding="wsHttpBinding"  
           bindingConfiguration="WSHttpBinding_IInmateCanteenServiceWeb"
           contract="InmateCanteenWeb.IInmateCanteenServiceWeb" />
       <endpoint name="WSHttpBinding_ICommAccountingBinding" 
           address="..."
           binding="wsHttpBinding" 
           bindingConfiguration="WSHttpBinding_IInmateCanteenServiceWeb"
           contract="CommAccountingWeb.ICommAccountingWeb" />
   </client>
</system.serviceModel>

和服务器

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="httpBehavior">
                <!--<webHttp />-->
            </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
           <behavior name="ServiceBehavior">
              <serviceCredentials>
                  <clientCertificate>
                     <authentication revocationMode="NoCheck" />
                  </clientCertificate>
                  <serviceCertificate findValue="CN=secure.inmatecanteen.com" />
              </serviceCredentials>
              <serviceMetadata httpsGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
           </behavior>
           <behavior name="MexBehavior">
               <serviceMetadata httpsGetEnabled="true" />
               <serviceDebug includeExceptionDetailInFaults="true" />
           </behavior>
           <behavior name="HttpMexBehavior">
                <serviceMetadata httpsGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
           </behavior>
           <behavior name="BasicHttpMexBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
           </behavior>
           <behavior name="">
                <serviceMetadata httpsGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
           </behavior>
        </serviceBehaviors>
      </behaviors>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="false" 
                                 multipleSiteBindingsEnabled="true" />
      <bindings>
         <wsHttpBinding>
            <binding name="myWsHttpBinding" maxBufferPoolSize="2147483647" 
                maxReceivedMessageSize="2147483647" messageEncoding="Text">
                <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
                       maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
                       maxNameTableCharCount="2147483647" />
                <security mode="Transport">
                    <transport clientCredentialType="None" />
                </security>
            </binding>
         </wsHttpBinding>
         <webHttpBinding>
             <binding name="myWebHttpBinding">
                <security mode="Transport">
                   <transport clientCredentialType="None" proxyCredentialType="None" 
                             realm=""  />
                </security>
            </binding>
         </webHttpBinding>
         <basicHttpBinding>
             <binding name="myBasicHttpBinding" maxBufferPoolSize="2147483647" 
                 maxReceivedMessageSize="2147483647">
                 <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
                        maxNameTableCharCount="2147483647" />
             </binding>
        </basicHttpBinding>
     </bindings>
     <services>
         <service name="CommAccountingWeb.CommAccountingWeb"  
                  behaviorConfiguration="HttpMexBehavior">
             <endpoint 
                 address="" 
                 behaviorConfiguration="httpBehavior" 
                 binding="webHttpBinding" bindingConfiguration="myWebHttpBinding" 
                 contract="CommAccountingWeb.ICommAccountingWeb" />
             <endpoint 
                 address="mex"
                 binding="mexHttpsBinding" 
                 contract="IMetadataExchange"  />
             <host>
                <baseAddresses>
                    <add baseAddress="..."></add>
                </baseAddresses>
             </host>
         </service>
         <service name="CommAccountingWeb.CommAccountingBasic" 
                  behaviorConfiguration="BasicHttpMexBehavior">
            <endpoint 
                address="" 
                binding="basicHttpBinding" 
                bindingConfiguration="myBasicHttpBinding" 
                contract="CommAccountingWeb.ICommAccountingBasic" />
            <endpoint 
                address="mex"
                binding="mexHttpBinding"  
                contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                  <add baseAddress="..." />
              </baseAddresses>
           </host>
        </service>
    </services>
</system.serviceModel>

推荐答案

我怀疑-您的客户端配置如下:

As I suspected - your client-side config looks like this:

  <endpoint name="WSHttpBinding_ICommAccountingBinding" 
       address="https://secure.inmatecanteen.com/CommAccountingService/CommAccountingWeb.svc"
       binding="wsHttpBinding" 
       bindingConfiguration="WSHttpBinding_IInmateCanteenServiceWeb"
       contract="CommAccountingWeb.ICommAccountingWeb" />

它期望 wsHttpBinding -但它连接到的服务器端地址是:

It expects wsHttpBinding - but the server-side address it's connecting to is:

 <service name="CommAccountingWeb.CommAccountingWeb"  
          behaviorConfiguration="HttpMexBehavior">
     <endpoint 
         address="" 
         behaviorConfiguration="httpBehavior" 
         binding="webHttpBinding" bindingConfiguration="myWebHttpBinding" 
         contract="CommAccountingWeb.ICommAccountingWeb" />
     <host>
        <baseAddresses>
           <add baseAddress="https://secure.inmatecanteen.com/CommAccountingService/CommAccountingWeb.svc"></add>
        </baseAddresses>
     </host>
 </service>

,此服务器端点使用 webHttpBinding .

因此,虽然客户端期望 SOAP XML消息(内容类型:application/soap+xml; charset=utf-8),但是服务器端端点是 REST 端点,该端点返回纯XML(内容类型:application/xml; charset=utf-8)

So while the client expects a SOAP XML message (content type: application/soap+xml; charset=utf-8), the server-side endpoint is a REST endpoint which returns plain XML (content type: application/xml; charset=utf-8)

解决方案:您需要确保所使用的客户端端点在绑定和配置方面都是同步的!

Solution: you need to make sure both the client and the server endpoint used are in sync with regards to bindings and configuration!

这篇关于响应消息的WCF charset = utf-8与绑定的内容类型不匹配(application/soap + xml; charset = utf-8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆