繁体   English   中英

响应消息的内容类型 application/xml;charset=utf-8 与绑定的内容类型(text/xml; charset=utf-8)不匹配,WCF

[英]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

我知道这个问题之前已经被问过几次,但是给出的解决方案要么对我不起作用,要么我太无知而无法完全理解如何实施该解决方案。

因此,我尝试运行的网站运行在 WCF 客户端之外。 每当尝试调用 WCF 服务(即,任何数据库搜索或编辑)时,都会出现此错误

内容类型 text/html; 响应消息的 charset=utf-8 与绑定的内容类型(text/xml;charset=utf-8)不匹配。 如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。 响应的前 1024 个字节是:'

当我通过未处理的异常发生此错误时,这就是弹出的内容

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

(注:最后截断的那一行是)

[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>

这是用于该站点的 web.config 文件(我不确定问题是否集中在这里,但我有一个唠叨的怀疑)

<?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>

现在,从我收集的其他问题来看,我收到的错误的要点不是从数据库获取 xml 响应,而是收到 html 页面错误。

在问这里之前,我一直在从网络主机的技术支持那里获得帮助,但此时他们不确定问题是什么(或者至少,我与之交谈的人不确定)我们使用 IIS 尝试修改系统中的某些设置(没有真正的改变),所以我可以安全地假设该站点托管在 IIS 上?

对此事的任何帮助都非常感谢。

您收到 500 错误。 这意味着错误是在托管服务的服务器上抛出的,而不是来自调用者。 我的猜测是向服务发送了错误数据,例如 null 或字符串而不是 int,或者未发送服务所需的所有必需位。

要获得更详细的错误,您要么必须

a) 在托管服务的服务器上运行相同的请求

例如 - 如果您对服务的调用是http://www.domain.com/service.svc?id=1 ,请让他们在托管服务的服务器上运行 URL 并向您发送错误。

b) 通过修改服务的 web.config 禁用自定义错误以获取实际错误

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM