【发布时间】:2014-12-05 19:26:56
【问题描述】:
我们遇到了 WCF 问题 - 尝试连接时出现以下错误。有很多关于各种配置的建议,在尝试了所有这些之后,我们可以使用一些帮助。
我们使用 HTTPS 来确保传输安全,使用从 GoDaddy 获得的真实 SSL 证书。当我们浏览网站上的网页时,它似乎已安装并正常工作。无需身份验证,我们就可以正确连接到我们的 WCF 服务。
对于身份验证,我们使用的是我们自己创建的客户端证书。这些客户端证书在我们切换到 HTTPS 之前运行良好,当时我们正在使用带有自签名服务器证书的消息安全性(这很痛苦,因为我们必须让客户端安装服务器证书)。
错误 客户端身份验证方案“匿名”禁止 HTTP 请求。 内部异常:远程服务器返回错误:(403) Forbidden
服务器配置文件
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="NewBinding0">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="WcfService1.Service1">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="NewBinding0" contract="WcfService1.IService1" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust" />
</clientCertificate>
<serviceCertificate findValue="....." x509FindType="FindByThumbprint" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add scheme="https" binding="wsHttpBinding" bindingConfiguration="NewBinding0" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
客户端配置文件
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="NewBehavior0">
<clientCredentials>
<clientCertificate findValue="customuser1"
storeName="TrustedPeople" x509FindType="FindBySubjectName" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="NewBinding0">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://www.insertoursitename.com/WcfService1/Service1.svc"
behaviorConfiguration="NewBehavior0" binding="wsHttpBinding"
bindingConfiguration="NewBinding0" contract="ServiceReference1.IService1"
name="wsHttpBinding_IService1" />
</client>
</system.serviceModel>
【问题讨论】:
-
服务器日志没有任何错误,客户端日志有:HTTP请求被客户端身份验证方案“匿名”禁止。
-
完整的 WCF 跟踪会在客户端和服务器端产生大量信息。如果您的服务器没有日志,那么您实际上并没有打开 WCF 跟踪。或者问题出在 IIS 中,请求甚至没有到达 WCF 服务,但即便如此,您应该在客户端上有更多日志。无论如何,请检查 IIS 服务器是否信任客户端证书(只需在服务器上打开客户端证书)。