简体   繁体   中英

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

I know this question has been asked a few times before, but the solutions given either don't work for me or I'm too ignorant to fully understand how to implement the solution.

So, the website I am attempting to run runs off of a WCF client. Whenever a WCF service tries to be called (ie, any database search or edit), it comes up with this 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). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '

When I make this error occur through an unhandled exception, this is what pops up

http://i.imgur.com/Vj7Baik.png

(Note: the line that cuts off at the end reads)

[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: '<!DOCTYPE html>

Here is the web.config file used for the site (I'm not sure whether the problem is centered here, but I have a nagging suspicion it is)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=DefaultConnection;Integrated Security=false;User ID=******;Password=******;"/>
    <add name="ITPDatabase" connectionString="Data Source=localhost;Initial Catalog=ITPDatabase;Integrated Security=false;User ID=******;Password=******;"/>
  </connectionStrings>
  <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Optimization" />
      </namespaces>
    <controls>
      <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
    </controls></pages>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" defaultUrl="~/" timeout="2880" />
    </authentication>
    <profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="DefaultRoleProvider">
      <providers>
        <add connectionStringName="DefaultConnection" applicationName="/"
          name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </providers>
    </roleManager>
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" />
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="defaultServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="defaultEndpointBehaviour">
        <webHttp/>
      </behavior>
    </endpointBehaviors>
    </behaviors>
    <services>
    <service name="*****.Service1" behaviorConfiguration="defaultServiceBehaviour">
      <endpoint address="" binding="wsHttpBinding" contract="ServiceReference1.IService1"></endpoint>
    <endpoint address="http://<domainname>.com/Service1.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
        contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>

    </service>

    </services>

    <client>
    <endpoint address="http://<domainname>.com/Service1.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
        contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
    </client>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
        <handlers accessPolicy="Read, Execute, Script">
            <add name="svc-Integrated" path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" resourceType="File" preCondition="integratedMode" />  </handlers>

    </system.webServer>


</configuration>

Now, from what I gathered of other questions, the gist of the error I'm receiving is instead of getting the xml response from the database, I'm getting a html page error.

Before asking here I've been getting help from the web host's tech support, but at this point they're not sure what the problem is (or at least, the person who I was talking to was unsure) We used IIS to attempt to tinker with certain settings in the system (to no real change) so I can safely assume the site is hosting on IIS?

Any help on the matter is greatly appeciated.

You are getting a 500 error. This means the error is being thrown on the server hosting the service and not from the caller. My guess is bad data being sent to the service, like a null or string instead of int, or not sending all the required bits the service requires.

To get a more detailed error, you will either have to

a) run the same request on the server hosting the service

eg - if your call to the service is http://www.domain.com/service.svc?id=1 , have them run the URL on the server where the service is hosted and send you the error.

b) disable custom errors to get the actual error by modifying the web.config of the service

<configuration>
  <system.webServer>
    <httpErrors errorMode="Detailed" />
  </system.webServer>
  <system.web>
    <customErrors mode="Off" />
    <compilation debug="true" />
  </system.web>
</configuration>

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 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 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 text/html; 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/html of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8) The content type text/plain of the response message does not match the content type of the binding (text/xml; charset=utf-8) WCF http binding error: The content type text/html does not match the content type of the binding (text/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 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' Cannot process the message because the content type 'application / xml' was not the expected type 'application / soap + xml; charset = utf-8 '
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM