<clientCertificate> 的 <certificate> 元素

指定用于对消息进行签名和加密的 X.509 证书。

架构层次结构

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <serviceBehaviors> 的 <behavior>
        <serviceCredentials>
          <serviceCredentials> 的 <clientCertificate>
            <clientCertificate> 的 <certificate> 元素

语法

<certificate findValue = "String" 
storeLocation = "CurrentUser/LocalMachine"
storeName="AddressBook/AuthRoot/CertificateAuthority/Disallowed/My/Root/TrustedPeople/TrustedPublisher"
X509FindType="FindByThumbPrint/FindBySubjectName/FindBySubjectDistinguishedName/FindByIssuerName/FindByIssuerDistinguishedName/FindBySerialNumber/FindByTimeValid/FindByTimeNotYetValid/FindByTemplateName/FindByApplicationPolicy/FindByCertificatePolicy/FindByExtension/FindByKeyUsage/FindBySubjectKeyIdentifier"
/>

属性和元素

以下几节描述了特性、子元素和父元素

属性

特性 说明

findValue

一个字符串,包含要在 X.509 证书存储中搜索的值。此属性中包含的类型必须满足指定 X509FindType 的要求。默认值为一个空字符串。

storeLocation

指定客户端可用于验证服务器证书的 X.509 证书存储的位置。包括以下有效值:

  • LocalMachine:分配给本地计算机的证书存储。

  • CurrentUser:分配给当前用户的证书存储。

默认值为 LocalMachine。

storeName

指定要打开的 X.509 证书存储的名称。包括以下有效值:

  • AddressBook:其他用户的证书存储。

  • AuthRoot:第三方证书颁发机构 (CA) 的证书存储。

  • CertificationAuthority:中间证书颁发机构 (CA) 的证书存储。

  • Disallowed:吊销的证书的证书存储。

  • My:个人证书的证书存储。

  • Root:受信任的根证书颁发机构 (CA) 的证书存储。

  • TrustedPeople:直接受信任的人和资源的证书存储。

  • TrustedPublisher:直接受信任的发行者的证书存储。

默认值为 My。

X509FindType

定义要执行的 X.509 搜索的类型。包括以下有效值:

  • FindByThumbPrint

  • FindBySubjectName

  • FindBySubjectDistinguishedName

  • FindByIssuerName

  • FindByIssuerDistinguishedName

  • FindBySerialNumber

  • FindByTimeValid

  • FindByTimeNotYetValid

  • FindByTemplateName

  • FindByApplicationPolicy

  • FindByCertificatePolicy

  • FindByExtension

  • FindByKeyUsage

  • FindBySubjectKeyIdentifier

findValue 属性中包含的类型必须满足指定 X509FindType 的要求。

默认值为 FindBySubjectDistinguishedName。

子元素

无。

父元素

元素 说明

<serviceCredentials> 的 <clientCertificate>

备注

当服务必须事先拥有客户端的证书才能与该客户端进行安全通信时,可使用 <certificate> 元素。使用双工通信模式时,会出现这种情况。在更为典型的请求/响应模式中,客户端会将其证书包含在请求中,服务将使用该证书对发送回客户端的响应进行加密和签名。但是,在双工通信模式中,服务没有来自客户端的请求,因此服务需要事先具有客户端的证书以确保发送到客户端的消息的安全。因此,您必须通过带外协商来获取客户端的证书,并使用此元素指定该证书。有关双工服务的更多信息,请参见How to: Create a Duplex Contract

示例

下面的代码指定如何在 <authentication> 元素中查找适当的 X.509 证书和自定义验证类型。

<serviceBehaviors>
 <behavior name="myServiceBehavior">
  <clientCertificate>
   <certificate 
         findValue="www.cohowinery.com" 
         storeLocation="CurrentUser" 
         storeName="TrustedPeople"
         x509FindType="FindByIssuerName" />
   <authentication customCertificateValidatorType="MyTypes.Coho"
    certificateValidationMode="Custom" 
    revocationMode="Offline"
    includeWindowsGroups="false" 
    mapClientCertificateToWindowsAccount="true" />
  </clientCertificate>
 </behavior>
</serviceBehaviors>

另请参见

参考

Certificate
Certificate
X509ClientCertificateCredentialsElement

其他资源

Security Behaviors in WCF
How To: Create a Service Employing a Custom Certificate Validator
Working with Certificates