简体   繁体   中英

The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)

I created WCF service and testing WCF client using stand alone application. I was able to view this service using Internet Explorer also able to view in Visual studio service references. Here is the error message.

"The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)."

Could you please advice what could be wrong?

Thank you.

Since the returned content type is text/html , I suspect your call result in a server-side error outside of WCF (you are receiving an HTML error page).

Try viewing the response with a web debugging proxy such as Fiddler .


(Edit based on comments) :

Based on your comments, I see that your WCF is hosted under Sharepoint 2010, in a form-authenticated site.

The error you are receiving is due to the fact that your your WCF client is NOT authenticated with sharepoint -- it does not have a valid authentication cookie. Sharepoint then return an HTTP Redirect to an html page (the login.aspx page); which is not expected by your WCF client.

To go further you will have to obtain an authentication cookie from Sharepoint (see Authentication Web Service ) and pass it to your WCF client.


(Updated edit) :

Mistake: The site is using claim based authentication.

Although this is not necessarily due to cookies or form authentication, the explaination of the provided error message remain the same. An authentication problem cause a redirection to an HTML page, which is not handled by the WCF client.

这可能会有所帮助,请检查ISS 7中的URL重写规则。如果您没有正确配置规则,则会出现此问题。

text/html is SOAP 1.1 header and Content-Type: application/soap+xml is SOAP 1.2 Verify your bindings and return header. It should be same either 1.1 or 1.2

Add the following code to the web.config server project

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="basicHttpBinding_IService">
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

<services>
  <service name="Service">
    <endpoint address="" name="BasicHttpBinding_IService"
              binding="basicHttpBinding"
              bindingConfiguration="basicHttpBinding_IService"
              contract="IService" />
  </service>

then update client web service,After the update, the following changes are made web.config

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService">
      <security mode="Transport" />
    </binding>
  </basicHttpBinding>
</bindings>


  <endpoint address="https://www.mywebsite.com/Service.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
    contract="Service.IService" name="BasicHttpBinding_IService" />

I hope to be useful

It sounds like your application is expecting XML but is receiving plain text. What type of object are you passing in?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question The content type text/xml; charset=“utf-8” of the response message does not match the content type of the binding (text/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 (text/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 (text/xml; charset=utf-8), WCF The content type text/plain of the response message does not match the content type of the binding (text/xml; charset=utf-8) wcf + The content type text/html of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8) WCF Service Client: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding WCF http binding error: The content type text/html does not match the content type of the binding (text/xml; charset=utf-8) C# ASMX Service throwing The content type text/html; charset=UTF-8 of the response message does not match the content type error HTTP 415 Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM