繁体   English   中英

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)

我在 IIS 7.5 中使用 .NET 4.0 托管 WCF 服务。 我还有一个 WPF 应用程序,我将其用作使用 Visual Studio 2010 和 .NET 4.0 构建的客户端。 我添加了我的服务参考,当我尝试调用 function 时,出现以下异常

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

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

我知道有很多关于此错误的谷歌结果,但似乎没有一个与我的具体问题相关/帮助。 我尝试安装非 HTTP 激活功能以及各种其他小技巧。 有人能帮忙吗? 谢谢

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

客户

<?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>

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

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

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

 <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

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

正如其中一条评论在这个问题中所说的那样,将?wsdl添加到客户端的端点地址,你应该有更多的运气。 ?wsdl很重要 - 这意味着浏览器只是获取服务的“Web服务描述语言”,而不是调用服务。

我有同样的问题,并添加?wsdl解决了我的头痛。

在为现有服务器端WebService之一创建客户端服务时,我遇到了类似的错误。 我可以在客户端上使用SOAP 1.1传输协议来纠正它。 不知何故肥皂1.2正在给予/期待不同的格式。 这回顾了BasicHttpBinding与WebHttpBinding与WsHttpBinding之间的区别。

在我添加了一个返回基类实例集合的方法之后,我遇到了这个问题,该基类没有[KnownType]属性可以解析为具体实例。 使用[KnownType]属性后,问题就消失了。

[ServiceContract]
public interface IService {
    [OperationContract]
    IEnumerable<ItemBase> GetItems();
}

[DataContract]
// [KnownType(typeof(RealItemA))] <--- without these attributes you will get a problem
// [KnownType(typeof(RealItemB))]
public class ItemBase {
}

[DataContract]
public class RealItemA : ItemBase {
}

[DataContract]
public class RealItemB : ITemBase {
}

在我的情况下,错误导致同样的错误

[datacontract] 
[datamember]

返回数据类型中的属性。

错误消息确实具有误导性。

确保您在添加服务引用时未在app.config中生成的绑定,合同和端点进行更改。

在.NET代码中将MessageEncoding添加为Mtom,然后检查是否仍然收到消息。

我已经尝试过解释使用soap协议为wshttpbinding和basichttpbinding创建wcf服务的消耗以及这里面临的问题: http ://www.writeulearn.com/consume-wcf-soap-service-csharp/请仔细阅读。

由于Syste.Web.MVC DLL的不同版本,我有这个错误。 您可以参考答案这里的另一个堆栈溢出问题。

在我的例子中,特定服务使用 SOAP 1.1 而不是通常的 1.2。
我不得不从这个改变绑定:

<system.serviceModel>
    <bindings>      
        <customBinding>
            <binding name="ServiceSoapBinding">
                <textMessageEncoding messageVersion="Soap12"/>
            </binding>
        </customBinding>
    </bindings>
</system.serviceModel>

对此:

<system.serviceModel>
    <bindings>      
        <customBinding>
            <binding name="ServiceSoapBinding">
                <textMessageEncoding messageVersion="Soap11"/>
            </binding>
        </customBinding>
    </bindings>
</system.serviceModel>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 wcf +响应消息的内容类型text / html与绑定的内容类型不匹配(application / soap + xml; charset = utf-8) Ajax:响应消息的内容类型text \\ / html与绑定的内容类型不匹配(application \\ / soap + xml; charset = utf-8) 响应消息的内容类型 application/xml;charset=utf-8 与绑定的内容类型(text/xml; charset=utf-8)不匹配,WCF 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8) 无法处理消息,因为内容类型 &#39;text/xml;charset=UTF-8&#39; 不是预期的类型 &#39;application/soap+xml; 字符集=utf-8&#39; 内容类型 text/xml; 响应消息的 charset=&quot;utf-8&quot; 与绑定的内容类型不匹配 (text/xml; charset=utf-8) 内容类型text / html; charset =响应消息的UTF-8与绑定的内容类型不匹配(text / xml; charset = utf-8) gSOAP转换为WCF。 应用程序/ soap + xml; 字符集= utf-8 WCF成员资格提供程序引发错误:内容类型&#39;application / json; charset = utf-8&#39;不是预期的类型&#39;application / soap + xml; 字符集= UTF-8&#39; WCF错误:(415)内容类型&#39;application / x-www-form-urlencoded&#39;不是预期类型&#39;application / soap + xml; 字符集= UTF-8&#39;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM