90

I've got a WCF Service running on my local IIS server. I've added it as a service reference to a C# Website Project and it adds fine and generates the proxy classes automatically.

However, when I try and call any of the service contracts, I get the following error:

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

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

I also have a console application which also communicates with the WCF Service and the console app is able to call methods fine without getting this error.

Below are excerpts from my config files.

WCF Service Web.Config:

<system.serviceModel>
   <services>
      <service name="ScraperService" behaviorConfiguration="ScraperServiceBehavior">
         <endpoint address=""
                   binding="wsHttpBinding" 
                   bindingConfiguration="WSHttpBinding_IScraperService"
                   contract="IScraperService" />
         <endpoint address="mex" 
                   binding="mexHttpBinding" 
                   contract="IMetadataExchange" />
         <host>
            <baseAddresses>
                <add baseAddress="http://example.com" />
            </baseAddresses>
         </host>
      </service>
   </services>
   <bindings>
       <wsHttpBinding>
           <binding name="WSHttpBinding_IScraperService"
                    bypassProxyOnLocal="false" transactionFlow="false"
                    hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000"
                    messageEncoding="Text" textEncoding="utf-8"
                    useDefaultWebProxy="true" allowCookies="false">
               <readerQuotas 
                     maxDepth="2000000" maxStringContentLength="2000000" 
                     maxArrayLength="2000000" maxBytesPerRead="2000000"
                     maxNameTableCharCount="2000000" />
               <reliableSession 
                     enabled="false" ordered="true" inactivityTimeout="00:10:00" />
               <security mode="Message">
                   <message clientCredentialType="Windows"
                            negotiateServiceCredential="true"
                            algorithmSuite="Default"
                            establishSecurityContext="true" />
               </security>
            </binding>
          </wsHttpBinding>
      </bindings>
      <behaviors>
          <serviceBehaviors>
              <behavior name="ScraperServiceBehavior">
                  <serviceMetadata httpGetEnabled="true" />
                  <serviceDebug includeExceptionDetailInFaults="true" />
              </behavior>
          </serviceBehaviors>
     </behaviors>
</system.serviceModel>

Website Project Service Client Web.Config:

<system.serviceModel>
   <bindings>
      <wsHttpBinding>
          <binding name="WSHttpBinding_IScraperService" 
              closeTimeout="00:01:00" openTimeout="00:01:00" 
              receiveTimeout="00:10:00" sendTimeout="00:01:00"
              bypassProxyOnLocal="false" transactionFlow="false" 
              hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
              messageEncoding="Text" textEncoding="utf-8"
              useDefaultWebProxy="true" allowCookies="false">
              <readerQuotas 
                  maxDepth="32" maxStringContentLength="8192" 
                  maxArrayLength="16384" maxBytesPerRead="4096" 
                  maxNameTableCharCount="16384" />
              <reliableSession enabled="false"
                  ordered="true" inactivityTimeout="00:10:00" />
              <security mode="Message">
                  <transport clientCredentialType="Windows" 
                       proxyCredentialType="None" realm="" />
                  <message clientCredentialType="Windows" 
                       negotiateServiceCredential="true"
                       algorithmSuite="Default" />
              </security>
          </binding>
       </wsHttpBinding>
    </bindings>
<client>
        <endpoint name="WSHttpBinding_IScraperService"
            address="http://example.com/ScraperService.svc"
            binding="wsHttpBinding" 
            bindingConfiguration="WSHttpBinding_IScraperService"
            contract="ScraperService.IScraperService" >
           <identity>
               <servicePrincipalName value="host/FreshNET-II" />
           </identity>
        </endpoint>
     </client>
</system.serviceModel>
2
  • 1
    How are you hosting this service?? In IIS ?? If so, then IIS dictates the service address - you cannot define your own base addresses (they're not used). So if you're in IIS, the address would be http://yourserver/virtualdirectory/ScrapperService.svc . Can you do a "View in Browser" on the *.svc file inside Visual Studio's Solution Explorer??
    – marc_s
    Mar 9, 2011 at 12:08
  • 1
    I tried to view the service from the IIS server and it returned a DNS error. Turned out that the service was only visible internally so when my client tried to access the service, it couldn't. All sorted, thanks!
    – Dan
    Mar 9, 2011 at 14:41

24 Answers 24

43

I had a similar issue. I resolved it by changing

<basicHttpBinding>

to

<basicHttpsBinding>

and also changed my URL to use https:// instead of http://.

Also in <endpoint> node, change

binding="basicHttpBinding" 

to

binding="basicHttpsBinding"

This worked.

5
  • 1
    This was it for me. The provider switched from HTTP to HTTPS.
    – Scottie
    Nov 19, 2018 at 17:12
  • That was my problem , The https instead of http. Dec 30, 2018 at 13:14
  • This answer saved me so much trouble. I had to use the SoapClient constructor that accepted a binding object and use an instance of BasicHttpsBinding. Would have never figured it out. Sep 8, 2020 at 13:24
  • Same for me as well - thanks - also had to change from HttpTransportBindingElement to HttpsTransportBindingElement I am thinking the issue arises when you hit a service behind a HTTP only load balancer?
    – levis84
    Apr 6, 2021 at 17:55
  • I've got the same error when I've hosted a WCF service in Azure App Service. In my case, issue was due to accessing http end point of app service having the setting HTTPS Only set to On. So, I've also followed above solution provided by @radkan to update WCF configurations to use https. Thank you.
    – BNJ
    Jan 27, 2023 at 6:58
32

Try browsing to http://localhost/ScraperService.svc in the web browser on the server hosting the service, using the same Windows credentials that the client normally runs under.

I imagine that IIS is displaying an html error message of some description instead of returning xml as expected.

This also can occur when you have an http proxy server that performs internet filtering. My experience with ContentKeeper is that it intercepts any http/https traffic and blocks it as "Unmanaged Content" - all we get back is an html error message. To avoid this, you can add proxy server exception rules to Internet Explorer so that the proxy doesn't intercept traffic to your site:

Control Panel > Internet Options > Connections > LAN Settings > Advanced > Proxy Settings

enter image description here

3
  • That did the trick. I logged onto the server and tried to view the service and I received a DNS error. Turns out that sites were only visible internally so when my WCF client tried to access the service, it couldn't and returned an error. Thanks for your help!
    – Dan
    Mar 9, 2011 at 14:40
  • I do not use proxy, but this answer inspired me to turn off in 'Automatically detect settings' in near previous proxy dialog, which helped Apr 29, 2014 at 13:41
  • You are a lifesaver! Jun 14, 2018 at 2:42
20

An HTML response from the web server normally indicates that an error page has been served instead of the response from the WCF service. My first suggestion would be to check that the user you're running the WCF client under has access to the resource.

3
  • 1
    How could I go about testing this? Both the WCF Client and the WCF Service are running on the same IIS server just under different domains during testing...
    – Dan
    Mar 9, 2011 at 10:04
  • Is the WCF client an ASP.NET application running under IIS? If so, this will probably be running as the Network Service account, which has minimum privileges. You will need to either allow this account access to the directory in IIS or configure the WCF client to run as a different windows account.
    – DaveRead
    Mar 9, 2011 at 14:53
  • What if the WCF client is a client test tool like soapUI or WCFStorm? Nov 21, 2012 at 15:01
6

what's going on is that you're trying to access the service using wsHttpBind, which use secured encrypted messages by default (secured Messages). On other hand the netTcpBind uses Secured encrypted channels. (Secured Transport)... BUT basicHttpBind, doesn't require any security at all, and can access anonymous

SO. at the Server side, Add\Change this into your configuration.

<bindings>
    <wsHttpBinding>
     <binding name="wsbind"> 
         <security mode="Message">
             <transport clientCredentialType="Windows" proxyCredentialType="None" />
             <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" establishSecurityContext="true" />
         </security>
     </binding>
    </wsHttpBinding>
</bindings>

then add change your endpoint to

<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsbind" name="wshttpbind" contract="WCFService.IService" > 

That should do it.

3

NOTE: If your target server endpoint is using secure socket layer (SSL) certificate

Change your .config setting from basicHttpBinding to basicHttpsBinding

I am sure, It will resolve your problem.

2

As with many, in my situation I was also getting this because of an error. And sadly I could just read the CSS of the html error page.

The source of my problem was also a rewrite rule on the server. It was rewriting http to https.

2

I tried all the suggestions above, but what worked in the end was changing the Application Pool managed pipeline from Integrated mode to Classic mode.
It runs in its own application pool - but it was the first .NET 4.0 service - all other servicves are on .NET 2.0 using Integrated pipeline mode. Its just a standard WCF service using is https - but on Server 2008 (not R2) - using IIS 7 (not 7.5) .

2

In my WCF serive project this issue is due to Reference of System.Web.Mvc.dll 's different version. So it may be compatibility issue of DLL's different version

When I use

System.Web.Mvc.dll version 5.2.2.0 -> it thorows the Error The content type text/html; charset=utf-8 of the response message

but when I use System.Web.Mvc.dll version 4.0.0.0 or lower -> it works fine.

I don't know the reason of different version DLL's issue but by changing the DLL's verison it works for me.

This Error even generate when you add reference of other Project in your WCF Project and this reference project has different version of System.Web.Mvc DLL or could be any other DLL.

2

I had a similar issue in my asp.net core 5 web api project to call a soap service. I resolved it by :

1.changing its url : return new System.ServiceModel.EndpointAddress("http://ourservice.com/webservices/service1.asmx?wsdl"); to https://ourservice.com/...

  1. use these config in its Reference.cs :
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
    {
        if ((endpointConfiguration == EndpointConfiguration.TaxReturnSoap))
        {
            System.ServiceModel.BasicHttpsBinding result = new System.ServiceModel.BasicHttpsBinding();
            result.TextEncoding = System.Text.Encoding.UTF8;
            result.MaxBufferSize = int.MaxValue;
            result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
            result.MaxReceivedMessageSize = int.MaxValue;
            result.AllowCookies = true;
            return result;
        }
        if ((endpointConfiguration == EndpointConfiguration.TaxReturnSoap12))
        {
            System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
            System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
            textBindingElement.WriteEncoding = System.Text.Encoding.UTF8;
            textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None);
            result.Elements.Add(textBindingElement);
            System.ServiceModel.Channels.HttpsTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
            httpBindingElement.AllowCookies = true;
            httpBindingElement.MaxBufferSize = int.MaxValue;
            httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
            result.Elements.Add(httpBindingElement);
            return result;
        }
        throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
    }
1

In my case a URL rewrite rule was messing with my service name, it was rewritten as lowercase and I was getting this error.

Make sure you don't lowercase WCF service calls.

1

You may want to examine the configuration for your service and make sure that everything is ok. You can navigate to web service via the browser to see if the schema will be rendered on the browser.

You may also want to examine the credentials used to call the service.

1

I had a similar situation, but the client config was using a basicHttpBinding. The issue turned out to be that the service was using SOAP 1.2 and you can't specify SOAP 1.2 in a basicHttpBinding. I modified the client config to use a customBinding instead and everything worked. Here are the details of my customBinding for reference. The service I was trying to consume was over HTTPS using UserNameOverTransport.

<customBinding>
    <binding name="myBindingNameHere" sendTimeout="00:03:00">
        <security authenticationMode="UserNameOverTransport" includeTimestamp="false">
            <secureConversationBootstrap />
        </security>
        <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
              messageVersion="Soap12" writeEncoding="utf-8">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </textMessageEncoding>
        <httpsTransport manualAddressing="false" maxBufferPoolSize="4194304"
              maxReceivedMessageSize="4194304" allowCookies="false" authenticationScheme="Basic"
              bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              keepAliveEnabled="true" maxBufferSize="4194304" proxyAuthenticationScheme="Anonymous"
              realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
              useDefaultWebProxy="true" requireClientCertificate="false" />
    </binding>
</customBinding>
1
  • where can I config username and password, it show "The username is not provided. Specify username in ClientCredentials." Aug 11, 2016 at 2:51
1

Even if you don't use network proxy, turning 'Automatically detect settings' in proxy dialog makes this exception go off.

enter image description here

1

If your are using both wshttpbinding along with https request, then i resolved it by using the below configuration change.

 <security mode="TransportWithMessageCredential">
                    <transport clientCredentialType="None" />
                    <message clientCredentialType="Certificate" />
                </security>
0

X++ binding = endPoint.get_Binding(); binding.set_UseDefaultWebProxy(false);

2
  • 1
    Is this your answer if so please explain how it solves the problem. Jan 29, 2014 at 10:10
  • sometime our program failed to find out the proxy sevrer because of some unknown reason in that case don't use the default proxy and set ip address of proxy in code. In that way it will start work
    – Danish
    May 6, 2014 at 13:18
0

Hy, In my case this error appeared because the Application pool of the webservice had the wrong 32/64 bit setting. So this error needed the following fix: you go to the IIS, select the site of the webservice , go to Advanced setting and get the application pool. Then go to Application pools, select it, go to "Advanced settings..." , select the "Enable 32 bit applications" and make it Enable or Disable, according to the 32/64 bit type of your webservice. If the setting is True, it means that it only allows 32 bit applications, so for 64 bit apps you have to make it "Disable" (default).

0

For me, it was the web app connection string pointing to the wrong database server.

0

In my case it was happening because my WCF web.config had a return character as its first line. It was even more frustrating because it was behind a load balancer and was happening only half the time (only one of the two web.configs had this problem).

1
  • That's pretty funny tbh
    – Sean T
    Oct 26, 2021 at 15:10
0

This error happens also when :

targetNamespace is wrongly defined in the wsdl or when the ns2 is wrongly defined in the response (different from the ns in the request) . For example request

<.. xmlns:des="http://zef/">

response

<ns2:authenticateResponse xmlns:ns2="http://xyz/">
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

0

One of the reasons for such unexpected behavior could be the presence of an additional DLL file with a different name in the bin folder, alongside your main MyService.dll. For example, a file named MyService_copy.dll. Removing this duplicate DLL from the bin folder may resolve the issue and result in smoother operation of the service.

-1

I solved this problem by setting UseCookies in web.config.

  <system.web>
    <sessionState cookieless="UseCookies" />

and setting enableVersionHeader

  <system.web>
    <httpRuntime targetFramework="4.5.1" enableVersionHeader="false" executionTimeout="1200" shutdownTimeout="1200" maxRequestLength="103424" />
-1

For me the issue was resolved when I commented the following line in Web.config

<httpErrors errorMode="Detailed" />
-4

My solution was rather simple: backup everything from the application, uninstall it, delete everything from the remaining folders (but not the folders so I won't have to grant the same permissions again) then copy back the files from the backup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.