none
WCF Client Error: 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)

    Question

  • Hi, I'm getting the following error when trying to call methods from my WCF Service from my C# Web Site Project:

    System.ServiceModel.ProtocolException: 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). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.

    I've also got a console app that also communicates with the same WCF Service and it works fine so it's not an error with the WCF methods itself, it seems like an error with the configuration of the service or the client. 

    Both my WCF Service and my Website WCF Client are hosted on the same IIS server at the moment but they will be moved to different servers once it's finished.

    WCF Service Web.Config:

    <system.serviceModel>
    	<behaviors>
    		<serviceBehaviors>
    			<behavior>
    				<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
    				<serviceMetadata httpGetEnabled="true"/>
    				<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
    				<serviceDebug includeExceptionDetailInFaults="true"/>
    			</behavior>
    		</serviceBehaviors>
    	</behaviors>
    	<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    </system.serviceModel>
    

    Website WCF Client Web.Config:

    <system.serviceModel>
    	<bindings>
    		<basicHttpBinding>
    			<binding name="BasicHttpBinding_IScraperService" 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>
    	</bindings>
    	<client>
    		<endpoint address="http://example.com/ScraperService/ScraperService.svc"
    			binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IScraperService"
    			contract="ScraperService.IScraperService" name="BasicHttpBinding_IScraperService" />
    	</client>
    </system.serviceModel>
    

    This is my first attempt at creating a WCF so it's all very new. Any help is much appreciated.

    Thanks.

    • Edited by Scrooby Wednesday, March 09, 2011 9:47 AM
    Tuesday, March 08, 2011 9:11 AM

Answers

  • Found the problem.

    I tried to view my service from the hosting server and I received a DNS error. Turns out that the site was only visible internally. So presumably when my client tried to access the methods, it too got the DNS error and returned the HTML page.

    Thanks for your help and advice.

    • Marked as answer by Scrooby Wednesday, March 09, 2011 2:44 PM
    Wednesday, March 09, 2011 2:43 PM

All replies

  • Check your IIS MIME Types settings. It probably has the file extension defined with a different content type.
    Tan Silliksaar milemarx.com
    Tuesday, March 08, 2011 10:55 AM
  • I've tried changing the mime types for .svc (I assume that's the one you meant) to "text/xml" for both the client and the service but it didn't make any difference. Any other ideas?
    Tuesday, March 08, 2011 12:53 PM
  • Not sure if this will help but this is the full error returned:

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ServiceModel.ProtocolException: 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). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<html>
    <head>
    <title>  </title>
    <script type="text/javascript">
    function bredir(d,u,r,v,c){var w,h,wd,hd,bi;var b=false;var p=false;var s=[[300,250,false],[250,250,false],[240,400,false],[336,280,false],[180,150,false],[468,60,false],[234,60,false],[88,31,false],[120,90,false],[120,60,false],[120,240,false],[125,125,false],[728,90,false],[160,600,false],[120,600,false],[300,600,false],[300,125,false],[530,300,false],[190,200,false],[470,250,false],[720,300,true],[500,350,true],[550,480,true]];if(typeof(window.innerHeight)=='number'){h=window.innerHeight;w=window.innerWidth;}else if(typeof(document.body.offsetHeight)=='number'){h=document.body.offsetHeight;w=document.body.offsetWidth;}for(var i=0;i<s.length;i++){bi=s[i];wd=Math.abs(w-bi[0]);hd=Math.abs(h-bi[1]);if(wd<=2&&hd<=2){b=true;p=bi[2];}}if(b||(w<100&&w!==0)||(h<100&&h!==0)){if(p&&self==parent){self.close();return;}return'/b'+'anner.php?w='+w+'&h='+h+'&d='+d+'&u='+u+'&r='+r+'&view='+v;}else{return c;}}
    </script>
    </head>
    <body onLoad="window.l'.

    Tuesday, March 08, 2011 4:09 PM
  • Scrooby,

    are you able to browse to service in IE?  and generate the wsdl?


    kashif
    Tuesday, March 08, 2011 6:45 PM
  • Is the service a WCF Service or does it run on a different platform?
    Tuesday, March 08, 2011 6:59 PM
  • Hello, seems an error occured when processing the request, and the response is an html page that contains the error message. Try to use Fiddler to monitor the request, and see what's in the response body.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Wednesday, March 09, 2011 2:41 AM
  • @Kpbutt Yes I can navigate to the service in IE and view the WSDL fine.

    @LOMECO It is a WCF Service.

    @Yi-Lun Luo I've downloaded Fiddler2 but I'm unsure of how to "monitor the request" are you able to provide any guidance on how to do this?

    On a side note, yesterday I changed the binding to use wsHttpBinding however I've now got a slightly different error now, it just expects a different response type:

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ServiceModel.ProtocolException: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<html>
    <head>
    <title>  </title>
    <script type="text/javascript">
    function bredir(d,u,r,v,c){var w,h,wd,hd,bi;var b=false;var p=false;var s=[[300,250,false],[250,250,false],[240,400,false],[336,280,false],[180,150,false],[468,60,false],[234,60,false],[88,31,false],[120,90,false],[120,60,false],[120,240,false],[125,125,false],[728,90,false],[160,600,false],[120,600,false],[300,600,false],[300,125,false],[530,300,false],[190,200,false],[470,250,false],[720,300,true],[500,350,true],[550,480,true]];if(typeof(window.innerHeight)=='number'){h=window.innerHeight;w=window.innerWidth;}else if(typeof(document.body.offsetHeight)=='number'){h=document.body.offsetHeight;w=document.body.offsetWidth;}for(var i=0;i<s.length;i++){bi=s[i];wd=Math.abs(w-bi[0]);hd=Math.abs(h-bi[1]);if(wd<=2&&hd<=2){b=true;p=bi[2];}}if(b||(w<100&&w!==0)||(h<100&&h!==0)){if(p&&self==parent){self.close();return;}return'/b'+'anner.php?w='+w+'&h='+h+'&d='+d+'&u='+u+'&r='+r+'&view='+v;}else{return c;}}
    </script>
    </head>
    <body onLoad="window.l'.

    Wednesday, March 09, 2011 8:59 AM
  • You need to change localhost to ipv4.fiddler in the service address. For example, http://ipv4.fiddler:someport/MyService.svc. Then run Fiddler, and invoke your service. You should see the request/response being captured. Please refer to http://www.developer.com/lang/jscript/article.php/3631066 for more information.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Wednesday, March 09, 2011 9:46 AM
  • The service isn't being run on my localhost, does it need to be if I want to run it through Fiddler?
    Wednesday, March 09, 2011 10:06 AM
  • Found the problem.

    I tried to view my service from the hosting server and I received a DNS error. Turns out that the site was only visible internally. So presumably when my client tried to access the methods, it too got the DNS error and returned the HTML page.

    Thanks for your help and advice.

    • Marked as answer by Scrooby Wednesday, March 09, 2011 2:44 PM
    Wednesday, March 09, 2011 2:43 PM