我在IIS 7.5中使用.NET 4.0托管WCF服务.我也有一个
WPF应用程序,我正在使用作为我的客户端,使用Visual Studio 2010和.NET 4.0构建.我添加了我的服务参考,当我尝试调用一个函数时,我得到以下异常
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绑定)之间似乎是一样的.
我知道有很多关于这个错误的谷歌搜索结果,但没有一个似乎是相关/帮助我的具体问题.我尝试安装非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>
我怀疑 – 您的客户端配置如下所示:
原文链接:https://www.f2er.com/xml/292792.html<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)时,服务器端端点是返回纯XML的REST端点(内容类型:application / xml; charset = utf- 8)
解决方案:您需要确保使用的客户端和服务器端点在绑定和配置方面都是同步的!