X509CertificateRecipientClientCredential.SetDefaultCertificate 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定要用于服务的默认证书。
重载
| 名称 | 说明 |
|---|---|
| SetDefaultCertificate(String, StoreLocation, StoreName) |
指定要用于服务的默认证书。 对于使用基于证书的消息安全性的绑定,此证书用于对服务的消息进行加密,服务预期会用于对客户端的答复进行签名。 |
| SetDefaultCertificate(StoreLocation, StoreName, X509FindType, Object) |
指定要用于服务的默认证书。 对于使用基于证书的消息安全性的绑定,此证书用于对服务的消息进行加密,服务预期会用于对客户端的答复进行签名。 |
注解
这些方法从与指定参数匹配的指定位置的存储区获取证书。
对于使用基于证书的消息安全性的绑定,此证书用于对服务的消息进行加密,服务预期会用于对客户端的答复进行签名。
SetDefaultCertificate(String, StoreLocation, StoreName)
指定要用于服务的默认证书。 对于使用基于证书的消息安全性的绑定,此证书用于对服务的消息进行加密,服务预期会用于对客户端的答复进行签名。
public:
void SetDefaultCertificate(System::String ^ subjectName, System::Security::Cryptography::X509Certificates::StoreLocation storeLocation, System::Security::Cryptography::X509Certificates::StoreName storeName);
public void SetDefaultCertificate(string subjectName, System.Security.Cryptography.X509Certificates.StoreLocation storeLocation, System.Security.Cryptography.X509Certificates.StoreName storeName);
member this.SetDefaultCertificate : string * System.Security.Cryptography.X509Certificates.StoreLocation * System.Security.Cryptography.X509Certificates.StoreName -> unit
Public Sub SetDefaultCertificate (subjectName As String, storeLocation As StoreLocation, storeName As StoreName)
参数
- subjectName
- String
使用者可分辨名称。
- storeLocation
- StoreLocation
服务用于获取服务证书的证书存储的位置。
- storeName
- StoreName
要打开的 X.509 证书存储的名称。
例外
subjectName 是 null。
尝试在凭据为只读时设置。
示例
以下代码使用此方法指定要使用的 X.509 证书。
public void snippet23(CalculatorClient cc)
{
X509CertificateRecipientClientCredential rcc = cc.ClientCredentials.ServiceCertificate;
rcc.SetDefaultCertificate("http://fabrikam.com/sts",
StoreLocation.CurrentUser,
StoreName.TrustedPeople);
}
注解
此方法从与参数匹配 subjectName 的指定位置的存储区获取证书。
storeLocation枚举中包含StoreLocation其值:
LocalMachine:分配给本地计算机的证书存储。
CurrentUser:当前用户使用的证书存储(默认值)。
如果应用程序在系统帐户下运行,则证书通常位于其中 LocalMachine。 如果应用程序在用户帐户下运行,则证书通常位于其中 CurrentUser。
枚举中包含storeName其StoreName值。
适用于
SetDefaultCertificate(StoreLocation, StoreName, X509FindType, Object)
指定要用于服务的默认证书。 对于使用基于证书的消息安全性的绑定,此证书用于对服务的消息进行加密,服务预期会用于对客户端的答复进行签名。
public:
void SetDefaultCertificate(System::Security::Cryptography::X509Certificates::StoreLocation storeLocation, System::Security::Cryptography::X509Certificates::StoreName storeName, System::Security::Cryptography::X509Certificates::X509FindType findType, System::Object ^ findValue);
public void SetDefaultCertificate(System.Security.Cryptography.X509Certificates.StoreLocation storeLocation, System.Security.Cryptography.X509Certificates.StoreName storeName, System.Security.Cryptography.X509Certificates.X509FindType findType, object findValue);
member this.SetDefaultCertificate : System.Security.Cryptography.X509Certificates.StoreLocation * System.Security.Cryptography.X509Certificates.StoreName * System.Security.Cryptography.X509Certificates.X509FindType * obj -> unit
Public Sub SetDefaultCertificate (storeLocation As StoreLocation, storeName As StoreName, findType As X509FindType, findValue As Object)
参数
- storeLocation
- StoreLocation
服务用于获取服务证书的证书存储位置。
- storeName
- StoreName
要打开的 X.509 证书存储的名称。
- findType
- X509FindType
要执行的 X.509 搜索的类型。
- findValue
- Object
要在 X.509 证书存储中搜索的值。
例外
findValue 是 null。
尝试在凭据为只读时设置。
示例
以下代码使用此方法指定要使用的 X.509 证书。
public void snippet22(CalculatorClient cc)
{
X509CertificateRecipientClientCredential rcc = cc.ClientCredentials.ServiceCertificate;
rcc.SetDefaultCertificate(StoreLocation.CurrentUser,
StoreName.TrustedPeople,
X509FindType.FindBySubjectName,
"FabrikamSTS");
}
注解
此方法从与和findType参数匹配findValue的指定位置的存储区获取证书。
storeLocation枚举中包含StoreLocation其值:
LocalMachine:分配给本地计算机的证书存储。
CurrentUser:当前用户使用的证书存储(默认值)。
如果应用程序在系统帐户下运行,则证书通常位于其中 LocalMachine。 如果应用程序在用户帐户下运行,则证书通常位于其中 CurrentUser。
枚举中包含storeName其StoreName值。
枚举中包含findType其X509FindType值。
最常用的枚举是 FindBySubjectName,它对指定存储区中证书的使用者名称进行不区分大小写的搜索。 这可以是不精确的搜索。 如果未找到与条件匹配的证书或多个证书,则会引发一个 InvalidOperationException 证书。