X509CertificateRecipientClientCredential.SetDefaultCertificate 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定服務所需的預設憑證。
多載
| 名稱 | Description |
|---|---|
| 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");
}
備註
此方法從指定位置的儲存庫取得與參數相符findTypefindValue的憑證。
列舉中包含storeLocation了 的StoreLocation值:
LocalMachine:分配給本地機器的憑證儲存庫。
CurrentUser:目前使用者使用的憑證儲存(預設)。
如果應用程式是以系統帳號執行,那麼憑證通常會放在 LocalMachine。 如果應用程式是以使用者帳號執行,那麼憑證通常會在 CurrentUser中。
的 storeName 值會包含在列 StoreName 舉中。
的 findType 值會包含在列 X509FindType 舉中。
最常用的列舉方式是 FindBySubjectName,它會對指定儲存庫中憑證的主體名稱進行不區分大小寫的搜尋。 這可能是一個不精確的搜尋。 若未找到符合條件的證書或多張證書,則會拋棄 A InvalidOperationException 。