0

I created a WCF service using c#4.0 and wcf 4.0, it is working fine locally. Tested using the WCf Test client and also using a console app as client. But after deploying the service I to do the same but it is giving the below error. I don't know what I'm doing wrong....

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:
' #content{ FONT-SIZE: 0.7em; PADDING-BOTTOM: 2em; MARGIN-LEFT: 30px}BODY{MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR: #000000; FONT-FAMILY: Verdana; BACKGROUND-COLOR: white}P{MARGIN-TOP: 0px; MARGIN-BOTTOM: 12px; COLOR: #000000; FONT-FAMILY: Verdana}PRE{BORDER-RIGHT: #f0f0e0 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f0f0e0 1px solid; MARGIN-TOP: -5px; PADDING-LEFT: 5px; FONT-SIZE: 1.2em; PADDING-BOTTOM: 5px; BORDER-LEFT: #f0f0e0 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: #f0f0e0 1px solid; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e5e5cc}.heading1{MARGIN-TOP: 0px; PADDING-LEFT: 15px; FONT-WEIGHT: normal; FONT-SIZE: 26px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 3px; MARGIN-LEFT: -30px; WIDTH: 100%; COLOR: #ffffff; PADDING-TOP: 10px; FONT-FAMILY: Tahoma; BACKGROUND-COLOR: #003366}.intro{MARGIN-LEFT: -15px} Test Service

Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory1 factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory
1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Calling the Service::

public static void Main(string[] args)
{

    TestClient user = new TestClient();  
    string id = "rSmith";
    string u = user.GetUserName(id);
    user.Close();
    Console.WriteLine("The User you Requested is "+ u+" .");
}

Service WebConfig.

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="NameSoap" 
               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>
    <mexHttpBinding>
      <binding name="NewBinding1"/>
    </mexHttpBinding>
  </bindings>
  <!--<client/>-->
  <services>
    <service behaviorConfiguration="MyServiceTypebehaviors" 
             name="Test">
      <endpoint address="" 
                binding="basicHttpBinding" 
                bindingConfiguration="UserNameSoap" 
                bindingNamespace="https:/abc.com/Services/Test/"
                contract="Test.ITest" />
      <endpoint address="mex" 
                binding="mexHttpBinding" 
                bindingConfiguration="NewBinding1"
                contract="IMetadataExchange" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="MyServiceTypebehaviors">
        <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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 aspNetCompatibilityEnabled="false"
                             multipleSiteBindingsEnabled="true"/>
</system.serviceModel>

Client Config File

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_ITest" />
    </basicHttpBinding>
  </bindings>
  <client>            
    <endpoint address="http://abc.com/Services/Test/Test.svc"
              binding="basicHttpBinding" 
              bindingConfiguration="BasicHttpBinding_ITest"
              contract="DevService.ITest" 
              name="BasicHttpBinding_ITest" />         
  </client>
</system.serviceModel>
Tim
  • 28,212
  • 8
  • 63
  • 76
Sri
  • 33
  • 1
  • 11
  • Please post your code (service and how you're calling it) plus the relevant config files. – Tim Sep 16 '13 at 18:11
  • Please google your problem before posting it to stackoverflow. Here are some similar problems and possible solutions i found: http://stackoverflow.com/questions/5263150/the-content-type-text-html-charset-utf-8-of-the-response-message-does-not-match http://stackoverflow.com/questions/5243929/wcf-service-client-the-content-type-text-html-charset-utf-8-of-the-response-me http://social.msdn.microsoft.com/Forums/vstudio/en-US/4b72d695-5790-4615-99cd-4e331d7e864d/wcf-returning-the-content-type-texthtml-of-the-response-message-does-not-match-the-content-type-of – Vinod Kumar Y S Sep 16 '13 at 18:13
  • 1
    have you tried updating your service reference and pointing it at the deployed service? – PatFromCanada Sep 16 '13 at 18:15
  • I did tried googlign and stackoverflow before and ttried all possible solution susggested but didn't gete the problem solved – Sri Sep 16 '13 at 18:28
  • I am able to find the Service using the Browser and aslo able to reference it but after invoking i Get the Response as mentioned above. – Sri Sep 16 '13 at 18:30
  • is your service reference in your startup project or is it in another project in the solution (class library) – PatFromCanada Sep 16 '13 at 19:34
  • Yes My Service Reference is in my Starup project... icreated a console App to Test teh Service....i tried making above mentioned Config Changes but still gets the same Message. – Sri Sep 17 '13 at 13:03

3 Answers3

0

Here the issue is "response message does not match the content type of the binding",

Check this link, its solved the issue:

http://forums.asp.net/t/1815638.aspx

Forum explain the actual issue, you can get the solution from Error consuming webservice, content type "application/xop+xml" does not match expected type "text/xml"

Community
  • 1
  • 1
Viji
  • 2,629
  • 1
  • 18
  • 30
  • it should returna Xml and im using the basicHttpBinding.. so i expect to use the Text Encoding.. – Sri Sep 17 '13 at 13:04
0

There are tough problems sometimes with this issue, but for me it is always a simple mismatch between the service reference and the service.

When you update your service reference it updates the web.config for that project. However, web config entries have no effect on your code if they are not in the startup project. So if your service reference is not in the startup project then when you refresh it you need to copy the relevant Client entries from the project with the reference to the startup project's web config Client section.

PatFromCanada
  • 2,738
  • 1
  • 27
  • 27
0

You have a contract mismatch between the client and the service:

Service contract: "Test.ITest"

<endpoint address="" 
          binding="basicHttpBinding" 
          bindingConfiguration="UserNameSoap" 
          bindingNamespace="https:/abc.com/Services/Test/"
          contract="Test.ITest" />

Client contract: "DevService.ITest"

<endpoint address="http://abc.com/Services/Test/Test.svc"
          binding="basicHttpBinding" 
          bindingConfiguration="BasicHttpBinding_ITest"
          contract="DevService.ITest" 
          name="BasicHttpBinding_ITest" />   

The client contract needs to match the service contract - in this case, Test.ITest. Even if Test.ITest and DevService.ITest are the same code, they'll be viewed as separate and distinct because of the namespaces.

Also, about 90% of the setting you've specified in your binding configurations are default, and you can safely omit them.

Tim
  • 28,212
  • 8
  • 63
  • 76
  • Here im DevService is defined onthe Client Side when adding a reference to project... we can name it it so do we have to match theNamespace with the of Service anemspace??? – Sri Sep 17 '13 at 13:07