我使用basicHttpBinding通过SSL在IIS 7中运行WCF服务。这就是绑定标记在客户端和服务器上的样子:
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyService"
messageEncoding="Mtom"
transferMode="Buffered">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpBinding>
在服务器端,这是行为标记:
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
一切正常。
现在,我想切换到证书凭证类型来验证客户端,这就是我被困住的地方。
我做了以下事情:
客户端和服务器的绑定标记现在如下所示:
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyService"
messageEncoding="Mtom"
transferMode="Buffered">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="Certificate" />
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpBinding>
对于客户:
<behaviors>
<endpointBehaviors>
<behavior name="clientCertificateEndpointBehavior">
<clientCredentials>
<clientCertificate storeName="My" storeLocation="CurrentUser" x509FindType="FindBySubjectName" findValue="Jackson Michael" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
在服务器端:
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication mapClientCertificateToWindowsAccount="true" certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck" />
</clientCertificate>
</serviceCredentials>
</behavior>
</behaviors>
客户端获取System.ServiceModel.Security.MessageSecurityException:从另一方收到了一个不安全或不正确安全的故障。请参阅内部FaultException以获取故障代码和详细信息。
使用Trace Viewer查看跟踪输出,我发现:
System.IdentityModel.Tokens.SecurityTokenValidationException:The X.509证书SN =杰克逊,G =迈克尔,OID.2.5.4.41 =杰克逊迈克尔, E = michaeljackson5@jacksons.com,CN = Jackson Michael,C = LK chain 建筑失败了。使用的证书具有信任链 无法验证。更换证书或更改 certificateValidationMode。认证链正确处理, 但政策提供者不信任其中一个CA证书。
如果我编辑serviceBehavior标记并设置certificateValidationMode =“None”,我会得到相同的结果。
问题是:
谢谢。