【发布时间】:2011-07-11 18:20:46
【问题描述】:
我的本地 IIS 服务器上运行了 WCF 服务。我已将它添加为对 C# 网站项目的服务引用,它可以很好地添加并自动生成代理类。
但是,当我尝试调用任何服务合同时,我收到以下错误:
说明:在执行过程中发生未处理的异常 执行当前的 Web 请求。 请查看堆栈跟踪以获取更多信息 有关错误和位置的信息 它起源于代码。
异常详情: System.ServiceModel.ProtocolException: 内容类型 text/html; 响应消息的charset=utf-8 与内容类型不匹配 绑定(应用程序/soap+xml; 字符集=utf-8)。如果使用自定义 编码器,请确保 IsContentTypeSupported 方法是 正确实施。第一个 1024 响应的字节数是:' 功能 bredir(d,u,r,v,c){var w,h,wd,hd,bi;var b=false;var p=false;var s=[[300,250,假],[250,250,假],[240,400,假],[336,280,假],[180,150,假],[468,60,假],[234,60,假],[ 88,31,假],[120,90,假],[120,60,假],[120,240,假],[125,125,假],[728,90,假],[160,600,假],[ 120,600,假],[300,600,假],[300,125,假],[530,300,假],[190,200,假],[470,250,假],[720,300,真],[500,350,真],[550,480, true]];if(typeof(window.innerHeight)=='number'){h=window.innerHeight;w=window.innerWidth;}否则 if(typeof(document.body.offsetHeight)=='number'){h=document.body.offsetHeight;w=document.body.offsetWidth;}for(var 我=0;我
我还有一个控制台应用程序,它也与 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,所以它是全新的。非常感谢任何帮助。
【问题讨论】:
-
您如何托管此服务?在 IIS 中?如果是这样,那么 IIS 规定了服务地址 - 您不能定义自己的基地址(它们不被使用)。因此,如果您在 IIS 中,地址将是
http://yourserver/virtualdirectory/ScrapperService.svc。您可以在 Visual Studio 的解决方案资源管理器中对 *.svc 文件执行“在浏览器中查看”吗?? -
我尝试从 IIS 服务器查看服务,但它返回了 DNS 错误。结果发现该服务仅在内部可见,因此当我的客户尝试访问该服务时,它不能。一切顺利,谢谢!
标签: c# .net wcf web-services