ServiceCredentials.ServiceCertificate 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得與此服務相關聯的目前憑證。
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 類別,然後建立會執行下列動作的單一複雜程式碼陳述式:
Credentials 屬性可用於存取 ServiceCredentials 的執行個體。
ServiceCredentials 執行個體接著叫用 ServiceCertificate。
ServiceCertificate 屬性會傳回 X509CertificateRecipientServiceCredential 物件,接著會在此物件上呼叫 SetCertificate 方法。
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 物件成員,指定要使用的憑證。
您也可以使用用戶端應用程式組態檔中的憑證 > 專案來設定此值。 <