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

tier1 picture tier1 · Dec 26, 2011 · Viewed 76.8k times · Source

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

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)

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).

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)

Client

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

and Server

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

Answer

marc_s picture marc_s · Dec 26, 2011

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" />

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>

and this server endpoint uses webHttpBinding.

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!