首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >WCF服务客户端:响应消息的内容类型text/html;charset=utf-8与绑定的内容类型不匹配

WCF服务客户端:响应消息的内容类型text/html;charset=utf-8与绑定的内容类型不匹配
EN

Stack Overflow用户
提问于 2011-03-09 17:47:42
回答 22查看 293.5K关注 0票数 80

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

但是,当我尝试调用任何服务契约时,我得到以下错误:

说明:当前web请求执行过程中发生未处理的异常。请查看堆栈跟踪,以了解有关错误的更多信息以及错误在代码中的来源。

应用程序异常详细信息: System.ServiceModel.ProtocolException:响应消息的内容类型文本/html;charset=utf-8与绑定的内容类型(应用程序/soap+xml;字符集=utf-8)不匹配。如果使用自定义编码器,请确保正确实现了IsContentTypeSupported方法。响应的前1024个字节是:‘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,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服务通信,并且控制台应用程序能够很好地调用方法,而不会得到这个错误。

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

WCF服务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,所以它是非常新的。任何帮助都是非常感谢的。

EN

回答 22

Stack Overflow用户

回答已采纳

发布于 2011-03-09 20:16:11

尝试在托管服务的服务器上的web浏览器中浏览到http://localhost/ScraperService.svc,使用与客户端正常运行时相同的Windows凭据。

我假设IIS正在显示某种描述的html错误消息,而不是像预期的那样返回xml。

当您有一个执行互联网过滤的http代理服务器时,也会发生这种情况。我使用ContentKeeper的经验是,它拦截任何http/https流量,并将其作为“非托管内容”进行拦截--我们得到的只是一条html错误消息。为了避免这种情况,您可以将代理服务器例外规则添加到Internet Explorer中,这样代理就不会截获到您站点的通信:

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

票数 30
EN

Stack Overflow用户

发布于 2016-08-02 02:39:50

我也遇到过类似的问题。我通过改变解决了这个问题

<basicHttpBinding>

<basicHttpsBinding>

我还将我的网址改为使用https://而不是http://.

同样在节点中,更改

binding="basicHttpBinding" 

binding="basicHttpsBinding"

这起作用了。

票数 32
EN

Stack Overflow用户

发布于 2011-03-09 17:51:08

来自web服务器的HTML响应通常表示已提供错误页面,而不是来自WCF服务的响应。我的第一个建议是检查正在运行WCF客户端的用户是否有权访问资源。

票数 19
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5243929

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档