WCF NetTcpBinding Transport安全模式(4)2014-06-26ClientCredentialType证书验证模式----基本配置在Transport安全模式下,客户端凭据支持三种类型:None、Windows、 Certificate。默认情况下采用Windows凭据类型。前面几个小节的示例中一直在 使用Windows凭据类型,本小节主要探讨Certificate凭据。 使用Certificate凭据,首先需要准备服务端和客户端证书。创建证书 的命令如图11-10所示。

图11-10 创建证书执行图11-10的命令,分别创建名为“XuanhunServer”和 “XuanhunClient”的两个证书,用于服务端和客户端,存储区为 “CurrentUser”。有了证书文件之后,需要修改相关的配置启用证书验证。在服务端的添加如代 码清单11-19所示的behaviors配置节,在behaviors配置节中配置服务端证书。代码清单11-19 配置服务器端证书
<behaviors> <serviceBehaviors> <behavior name="validateBehavior"> <serviceCredentials> <serviceCertificate x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" findValue=" XuanhunServer" /> <clientCertificate > <authentication certificateValidationMode="None" trustedStoreLocation="CurrentUser" /> <certificate /> </clientCertificate> </serviceCredentials> </behavior> </serviceBehaviors> </behaviors>
在以上代码中,serviceCredentials节用来添加服务端证书配置,该节包含多 个serviceCertificate节,用来指定具体的服务端证书实例。 serviceCredentials配置节可配置的凭据信息参看11.1.3节。serviceCertificate基本语法如代码清单11-20所示。代码清单11-20 serviceCertificate基本语法
<serviceCertificate findValue="String"storeLocation="LocalMachine/CurrentUser"storeName="AddressBook/AuthRoot/CertificateAuthority/Disallowed/My/Root/TrustedPeople/TrustedPublisher"X509FindType="FindByThumbprint/FindBySubjectName/FindBySubjectDistinguishedName/FindByIssuerName/FindByIssuerDistinguishedName/FindBySerialNumber/FindByTimeValid/FindByTimeNotYetValid/FindByTemplateName/FindByApplicationPolicy/FindByCertificatePolicy/FindByExtension/FindByKeyUsage/FindBySubjectKeyIdentifier"/>
serviceCertificate包含的属性及描述如表11-7所示。表11-7 serviceCertificate属性
