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

一个 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 对象的成员。

还可以使用客户端应用程序配置文件中的证书>元素设置此值。<

适用于