共用方式為


ServiceCredentials.ServiceCertificate 屬性

定義

取得與此服務相關聯的目前憑證。

public:
 property System::ServiceModel::Security::X509CertificateRecipientServiceCredential ^ ServiceCertificate { System::ServiceModel::Security::X509CertificateRecipientServiceCredential ^ get(); };
public System.ServiceModel.Security.X509CertificateRecipientServiceCredential ServiceCertificate { get; }
member this.ServiceCertificate : System.ServiceModel.Security.X509CertificateRecipientServiceCredential
Public ReadOnly Property ServiceCertificate As X509CertificateRecipientServiceCredential

屬性值

X509CertificateRecipientServiceCredential 執行個體。

範例

這個程式碼會顯示如何指定服務使用的憑證。

先建立 ServiceHost 類別,然後建立會執行下列動作的單一複雜程式碼陳述式:

Uri a = new Uri("net.tcp://MyMachineName/tcpBase");
Uri[] baseAddresses = new Uri[] { a };
ServiceHost sh = new ServiceHost(typeof(SayHello), baseAddresses);
sh.AddServiceEndpoint(c, b, "Aloha");
sh.Credentials.ServiceCertificate.SetCertificate(
    StoreLocation.LocalMachine,
    StoreName.My,
    X509FindType.FindByThumbprint,
    "af1f50b20cd413ed9cd00c315bbb6dc1c08da5e6");
sh.Open();

備註

您可以呼叫此屬性傳回的 X509CertificateRecipientServiceCredential 物件成員,指定要使用的憑證。

您也可以使用用戶端應用程式組態檔中的憑證 > 專案來設定此值。 <

適用於