Dan*_*lis 62 .net c# wcf web-services
我在我的本地IIS服务器上运行了一个WCF服务.我已将其添加为C#Website Project的服务引用,并且它会添加正常并自动生成代理类.
但是,当我尝试调用任何服务合同时,我收到以下错误:
描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息: System.ServiceModel.ProtocolException:内容类型text/html; 所述响应消息不匹配的结合(;字符集= UTF-8应用/肥皂+ 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 = [[ 300250,假],[250250,假],[240400,假],[336280,假],[180150,假],[468,60,假],[234,60,假],[88,31,假],[120,90,假],[120,60,假],[120240,假],[125125,假],[728,90,假],[160600,假],[120600,假] [300600,假],[300125,假],[530300,假],[190200,假],[470250,假],[720300,真],[500350,真],[550480,真]]; 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>
Run Code Online (Sandbox Code Playgroud)
网站项目服务客户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>
Run Code Online (Sandbox Code Playgroud)
这是我第一次尝试创建一个WCF,所以这一切都很新.任何帮助深表感谢.
she*_*tie 27
尝试使用客户端通常运行的相同Windows凭据,在托管服务的服务器上的Web浏览器中浏览到http://localhost/ScraperService.svc.
我想IIS正在显示某些描述的html错误消息,而不是按预期返回xml.
当您具有执行Internet过滤的http代理服务器时,也会发生这种情况.我对ContentKeeper的体验是拦截任何http/https流量并将其阻止为"非托管内容" - 我们得到的只是一条HTML错误消息.为避免这种情况,您可以将代理服务器例外规则添加到Internet Explorer,以便代理不会拦截您网站的流量:
控制面板> Internet选项>连接>局域网设置>高级>代理设置

小智 13
我有类似的问题.我通过改变来解决它
<basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)
至
<basicHttpsBinding>
Run Code Online (Sandbox Code Playgroud)
并且还将我的URL更改为使用https://而不是http://.
同样在<endpoint>节点中,进行更改
binding="basicHttpBinding"
Run Code Online (Sandbox Code Playgroud)
至
binding="basicHttpsBinding"
Run Code Online (Sandbox Code Playgroud)
这很有效.
小智 5
发生了什么事情是你试图使用wsHttpBind访问服务,wsHttpBind默认使用安全加密邮件(安全邮件).另一方面,netTcpBind使用安全加密通道.(安全传输)...但是BasicHttpBind,根本不需要任何安全性,并且可以访问匿名
所以.在服务器端,添加\将其更改为您的配置.
<bindings>
<wsHttpBinding>
<binding name="wsbind">
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
然后添加更改您的端点
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsbind" name="wshttpbind" contract="WCFService.IService" >
Run Code Online (Sandbox Code Playgroud)
应该这样做.
| 归档时间: |
|
| 查看次数: |
237529 次 |
| 最近记录: |