WCF服务客户端:内容类型text/html;响应消息的 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

查看:39
本文介绍了WCF服务客户端:内容类型text/html;响应消息的 charset=utf-8 与绑定的内容类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WCF 服务在我的本地 IIS 服务器上运行.我已将它添加为 C# 网站项目的服务引用,它添加得很好并自动生成代理类.

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:

说明:在执行过程中发生了未处理的异常执行当前的 Web 请求.请查看堆栈跟踪以了解更多信息有关错误和位置的信息它起源于代码.

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.

异常详情: System.ServiceModel.ProtocolException:内容类型 text/html;响应消息的字符集=utf-8与内容类型不匹配绑定(应用程序/soap+xml;字符集=utf-8).如果使用自定义编码器,请确保IsContentTypeSupported 方法是正确实施.第一个1024响应的字节为:'功能bredir(d,u,r,v,c){var w,h,wd,hd,bi;varb=false;var p=false;vars=[[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,5,0],80true]];if(typeof(window.innerHeight)=='number'){h=window.innerHeight;w=window.innerWidth;}elseif(typeof(document.body.offsetHeight)=='number'){h=document.body.offsetHeight;w=document.body.offsetWidth;}for(var我=0;我

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

我还有一个控制台应用程序,它也与 WCF 服务通信,并且控制台应用程序能够正常调用方法而不会出现此错误.

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 服务 Web.Config:

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>

网站项目服务客户端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>

这是我第一次尝试创建 WCF,所以一切都很新.非常感谢任何帮助.

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

推荐答案

尝试浏览到 http://localhost/ScraperService.svc 在托管服务的服务器上的 Web 浏览器中,使用客户端通常在其下运行的相同 Windows 凭据.

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.

我想 IIS 正在显示一些描述的 html 错误消息,而不是按预期返回 xml.

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

当您有一个执行 Internet 过滤的 http 代理服务器时,也会发生这种情况.我对 ContentKeeper 的体验是它拦截任何 http/https 流量并将其作为非托管内容"阻止——我们得到的只是一条 html 错误消息.为避免这种情况,您可以向 Internet Explorer 添加代理服务器例外规则,以便代理不会拦截到您网站的流量:

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:

控制面板 > Internet 选项 > 连接 > LAN 设置 > 高级 > 代理设置

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

这篇关于WCF服务客户端:内容类型text/html;响应消息的 charset=utf-8 与绑定的内容类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆