【发布时间】:2019-05-26 11:06:02
【问题描述】:
我有一个自托管的 wcf 服务,它使用带有传输安全性的 wsHttpBinding。我希望该服务使用证书对客户端进行身份验证。
当客户端使用设置为“无”的 clientCredentialsType 与服务通信时,一切正常。 该证书是使用 OpenSSL(自签名)创建的,并在特定端口上使用 netsh 注册。证书的名称是 DomainName(在我的例子中是机器名称)。
更新
我已经为客户端和服务器创建了证书,并将它们放置在彼此的受信任根存储中(客户端存储中的服务器证书,反之亦然)。
我在 SOF 浏览了很多文章和其他问题,但即使是看起来相关的文章也无法帮助我解决问题。
当前配置
服务
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" httpsHelpPageEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="httpsBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" sendTimeout="01:00:00">
<security mode="Transport" >
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="serviceBehavior" name="Service">
<endpoint binding="wsHttpBinding" bindingConfiguration="httpsBinding" contract="SomeNamespace.IService"/>
<host>
<baseAddresses>
<add baseAddress="https://domain:port/Something/"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
客户
<system.serviceModel>
<client>
<endpoint address="https://domain:port/Something/"
behaviorConfiguration="endpointCredentialBehavior"
binding="wsHttpBinding"
bindingConfiguration="Binding"
contract="SomeNamespace.IService"/>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="endpointCredentialBehavior">
<clientCredentials>
<clientCertificate findValue="DomainName"
storeLocation="LocalMachine"
storeName="My"
x509FindType="FindBySubjectName" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="Binding">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
我得到以下异常:
System.ServiceModel.Security.MessageSecurityException:HTTP 请求被客户端身份验证方案“匿名”禁止。 ---> System.Net.WebException:远程服务器返回错误:(403)禁止。 在 System.Net.HttpWebRequest.GetResponse() 在 System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan 超时)
【问题讨论】:
标签: .net wcf wcf-binding wcf-security wcf-client