WCF服务客户端:内容类型text / html;字符集= 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

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

问题描述

我有我的本地IIS服务器上运行的WCF服务。我已经添加它作为一个服务引用到C#的网站项目,并将其添加精美,并自动生成的代理类。

然而,当我尝试调用任何服务合约,我得到以下错误:

  

说明:期间,出现未处理的异常   执行当前Web请求。   请查看更多堆栈跟踪   有关该错误以及信息   它起源于code。

     

异常详细信息: System.ServiceModel.ProtocolException:   内容类型text / html;   字符集= UTF-8的响应消息   不匹配的内容类型   结合(应用程序/肥皂+ XML;   字符集= UTF-8)。如果使用自定义   EN codeR,可以肯定的是,   IsContentTypeSupported方法   正确实施。第1024   响应的字节是:'        功能   bredir(D,U,R,V,C){VAR W,H,WD,高清,双向; 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;我

我也有一个控制台应用程序,这也与WCF服务进行通信,并在控制台应用程序可以调用精细的方法没有得到这个错误。

下面是我的配置文件摘录。

WCF服务Web.Config:

 < system.serviceModel>
   <服务>
      <服务名称=ScraperServicebehaviorConfiguration =ScraperServiceBehavior>
         <端点地址=
                   绑定=的wsHttpBinding
                   bindingConfiguration =WSHttpBinding_IScraperService
                   合同=IScraperService/>
         <端点地址=MEX
                   绑定=mexHttpBinding
                   合同=IMetadataExchange接口/>
         <主机>
            < baseAddresses>
                <新增baseAddress =htt​​p://example.com/>
            < / baseAddresses>
         < /主机>
      < /服务>
   < /服务>
   <绑定>
       <的wsHttpBinding>
           <绑定名称=WSHttpBinding_IScraperService
                    bypassProxyOnLocal =假transactionFlow =假
                    hostNameComparisonMode =StrongWildcard
                    maxBufferPoolSize =2000000maxReceivedMessageSize =2000000
                    messageEncoding =文本textEncoding =UTF-8
                    useDefaultWebProxy =真allowCookies =假>
               < readerQuotas
                     MAXDEPTH =2000000maxStringContentLength =2000000
                     maxArrayLength =2000000maxBytesPerRead =2000000
                     maxNameTableCharCount =2000000/>
               <的ReliableSession
                     启用=假责令=真正的inactivityTimeout =00:10:00/>
               <安全模式=消息>
                   <消息clientCredentialType =窗口
                            negotiateServiceCredential =真
                            algorithmSuite =默认
                            establishSecurityContext =真/>
               < /安全>
            < /装订>
          < /的wsHttpBinding>
      < /绑定>
      <行为>
          < serviceBehaviors>
              <行为NAME =ScraperServiceBehavior>
                  < serviceMetadata httpGetEnabled =真/>
                  < serviceDebug includeExceptionDetailInFaults =真/>
              < /行为>
          < / serviceBehaviors>
     < /行为>
< /system.serviceModel>
 

网站项目服务客户端 Web.config中

 < system.serviceModel>
   <绑定>
      <的wsHttpBinding>
          <绑定名称=WSHttpBinding_IScraperService
              closeTimeout =00:01:00openTimeout =00:01:00
              receiveTimeout =〇点10分零零秒的SendTimeout =○时01分00秒
              bypassProxyOnLocal =假transactionFlow =假
              hostNameComparisonMode =StrongWildcard
              maxBufferPoolSize =524288maxReceivedMessageSize =65536
              messageEncoding =文本textEncoding =UTF-8
              useDefaultWebProxy =真allowCookies =假>
              < readerQuotas
                  MAXDEPTH =32maxStringContentLength =8192
                  maxArrayLength =16384maxBytesPerRead =4096
                  maxNameTableCharCount =16384/>
              <启用的ReliableSession =假
                  责令=真inactivityTimeout =零时10分零零秒/>
              <安全模式=消息>
                  <交通运输clientCredentialType =窗口
                       proxyCredentialType =无的境界=/>
                  <消息clientCredentialType =窗口
                       negotiateServiceCredential =真
                       algorithmSuite =默认/>
              < /安全>
          < /装订>
       < /的wsHttpBinding>
    < /绑定>
<客户端>
        <端点名称=WSHttpBinding_IScraperService
            地址=htt​​p://example.com/ScraperService.svc
            绑定=的wsHttpBinding
            bindingConfiguration =WSHttpBinding_IScraperService
            合同=ScraperService.IScraperService>
           <身份>
               <的servicePrincipalName值=主机/ FreshNET-II/>
           < /身分>
        < /端点>
     < /客户>
< /system.serviceModel>
 

这是我创造一个WCF所以一切都非常新的第一次尝试。任何帮助是非常AP preciated。

感谢。

解决方案

用药品来 HTTP://localhost/ScraperService.svc 在在服务器上的Web浏览器承载服务,使用相同的Windows凭据客户端正常下运行。

我想,IIS显示的是一些描述,而不是返回XML作为预期的HTML错误消息。

当您有执行互联网过滤HTTP代理服务器这也可能发生。我与ContentKeeper的经验是,它拦截任何HTTP / HTTPS流量,并将其阻止作为不受管理的内容 - 所有我们得到的回复是一个HTML错误消息。为了避免这种情况,你可以添加代理服务器例外规则到Internet Explorer这样的代理不拦截流量到您的网站:

控制面板> Internet选项>连接>局域网设置>高级>代理服务器设置

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>

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

Thanks.

解决方案

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

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

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