共用方式為


X509CertificateRecipientClientCredential.SetDefaultCertificate 方法

定義

指定用於服務的預設憑證。

多載

SetDefaultCertificate(String, StoreLocation, StoreName)

指定用於服務的預設憑證。 對於使用以憑證為基礎之訊息安全性的繫結,這個憑證會用來加密傳送給服務的訊息,而且預期會被服務用來簽署對用戶端的回覆。

SetDefaultCertificate(StoreLocation, StoreName, X509FindType, Object)

指定用於服務的預設憑證。 對於使用以憑證為基礎之訊息安全性的繫結,這個憑證會用來加密傳送給服務的訊息,而且預期會被服務用來簽署對用戶端的回覆。

備註

這些方法會從符合所指定參數之指定位置的存放區中取得憑證。

對於使用以憑證為基礎之訊息安全性的繫結,這個憑證會用來加密傳送給服務的訊息,而且預期會被服務用來簽署對用戶端的回覆。

SetDefaultCertificate(String, StoreLocation, StoreName)

來源:
X509CertificateRecipientClientCredential.cs
來源:
X509CertificateRecipientClientCredential.cs
來源:
X509CertificateRecipientClientCredential.cs

指定用於服務的預設憑證。 對於使用以憑證為基礎之訊息安全性的繫結,這個憑證會用來加密傳送給服務的訊息,而且預期會被服務用來簽署對用戶端的回覆。

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 憑證存放區名稱。

例外狀況

subjectNamenull

已嘗試設定認證何時是唯讀的。

範例

下列程式碼會使用這個方法來指定要使用的 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)

來源:
X509CertificateRecipientClientCredential.cs
來源:
X509CertificateRecipientClientCredential.cs
來源:
X509CertificateRecipientClientCredential.cs

指定用於服務的預設憑證。 對於使用以憑證為基礎之訊息安全性的繫結,這個憑證會用來加密傳送給服務的訊息,而且預期會被服務用來簽署對用戶端的回覆。

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 憑證存放區內搜尋的值。

例外狀況

findValuenull

已嘗試設定認證何時是唯讀的。

範例

下列程式碼會使用這個方法來指定要使用的 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 列舉型別中。

最常用的列舉型別 (Enumeration) 是 FindBySubjectName,它會針對指定之存放區內憑證的主體名稱進行不區分大小寫的搜尋。 這可以是不精確的搜尋。 如果找不到憑證,或找到多個符合準則的憑證,將會擲回 InvalidOperationException

適用於