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 对象的成员。
还可以使用客户端应用程序配置文件中的证书>元素设置此值。<