16

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.

SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
nav100
  • 411
  • 1
  • 10
  • 26

6 Answers6

19

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.

Sam B
  • 2,441
  • 2
  • 18
  • 20
  • Sorry it took me so long to come to this issue. Thanks for the reply. Here is some data from Fiddler. – nav100 Mar 14 '11 at 18:32
  • Here is some data Headers from Fiddler. GET /_vti_bin/psi/helloservice.svc HTTP/1.1 Content-Type: text/xml; charset=utf-8 MicrosoftSharePointTeamServices: 14.0.0.4762 Server: Microsoft-IIS/7.5 X-AspNet-Version: 2.0.50727 X-SharePointHealthScore: 4 – nav100 Mar 14 '11 at 18:33
  • @nav100: Try running your application and reproduce the stated error with Fiddler running. You may have to modify your WCF client endpoints and configuration for WCF to connect through Fiddler. – Sam B Mar 14 '11 at 18:43
  • How can I connect through Fiddler? I entered http://server/pwa/_vti_bin/psi/helloservice.svc Fiddler RequestHeader. I got the same information. – nav100 Mar 14 '11 at 19:18
  • @nav100: if you've seen the call in fiddler, then you're OK. The header you pasted reported a `Content-Type` of `text/xml`; which is what we expect. Did you receive the exception you stated in your question during those calls? If no, can you manage to reproduce it? Note they may be multiple lines for a WCF call in fiddler. Look for `text/html` returned content-type and inspect the content for more clues. – Sam B Mar 14 '11 at 19:24
  • Yes, I am still getting this exception. The response webview displays the following error message. " Object moved to – nav100 Mar 14 '11 at 19:46
  • But it works fine in IE. This is only a problem with the client application. – nav100 Mar 14 '11 at 19:53
  • @nav100: It work in IE because your current browser session is already authenticated with the sharepoint site. The client application does not share this session; which is why you must authenticate it manually. – Sam B Mar 14 '11 at 20:04
  • Sam, Do I have to use this code. It looks like it's using Windows Authentication. I will try the following code.Authentication authSvc = new Authentication(); authSvc.Url = @"http:///_vti_bin/Authentication.asmx"; authSvc.Credentials = CredentialCache.DefaultCredentials; authSvc.CookieContainer = new CookieContainer() authSvc.AllowAutoRedirect = true; LoginResult result = authSvc.Login(strDomain + @"\" +username, password); – nav100 Mar 14 '11 at 20:06
  • @nav100: I made the form-auth assumption based on the fact you are being redirected to the login page. You should not have to authenticate the call to the Authentication web service -- it is anonymously available. However, if you are sure the site is in Windows authentication, I may have other advices. – Sam B Mar 14 '11 at 20:13
  • I am pretty sure it's windows authentication. I never entered any credentials to login to Sharepoint central admin. Where can I check for authentication? Thanks again for your help. I am stuck with this error. – nav100 Mar 14 '11 at 20:36
  • @nav100: You can check this through the Sharepoint central admin - application management - authentication providers (for the correct web application). I'm not sure of the exact location of this page, I only have a WSS 3.0 available at the moment. Anyway, if you do not have to enter your credentials when connecting the the site where your WCF is hosted, you are in windows auth. In this case, please update the question with the client code wich perform the call and the system.serviceModel client config section. – Sam B Mar 14 '11 at 20:43
  • It's using claims based authentication. – nav100 Mar 14 '11 at 20:50
  • Oh! Unfortunately I did not played with claims based authentication yet :( At least now you know where is your exception coming from! I suggest you to search and/or open another question especially on "cosuming Sharepoint 2010 claim-based WCF". Good luck! – Sam B Mar 14 '11 at 20:56
  • Thanks for your time. I appreaciate your help. – nav100 Mar 14 '11 at 21:03
  • @nav100: you're welcome :) If you think this was the answer to your original question, feel free to accept it :) – Sam B Mar 14 '11 at 21:06
  • Can you please provide some insight on this: http://stackoverflow.com/questions/41752213/why-is-asmx-giving-an-error-when-pulling-data-using-client-script – Si8 Jan 20 '17 at 14:12
3

This may be helpful, check the url rewrite rules in ISS 7. This issue will occur if is you didn't configure rule properly.

  • This was my problem. I was redirecting calls to my http wcf service to the https version. The problem (that I noticed in Fiddler) was that my service call was receiving an html page with a link to the URL that the URL Rewrite was redirecting to - thus receiving html instead of the expected XML. – Dave Oct 27 '15 at 09:32
0

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

Taran
  • 2,895
  • 25
  • 22
0

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

vajihe
  • 1
  • 1
0

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

smartcaveman
  • 41,281
  • 29
  • 127
  • 212
0

i was getting this error in NavitaireProvider while calling BookingCommit service (WCF Service Reference)

so, when we get cached proxy object then it will also retrived old SigninToken which still may not be persisted so that not able to authenticate

so as a solution i called Logon Service when i get this exception to retrieve new Token