X509CertificateRecipientServiceCredential.Certificate Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the certificate to use for representing the service when communicating back to the client.

Namespace:   System.ServiceModel.Security
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public X509Certificate2 Certificate { get; set; }

Property Value

Type: System.Security.Cryptography.X509Certificates.X509Certificate2

The X509Certificate2 to use for representing the service when communicating back to the client.

Exception Condition
InvalidOperationException

Attempted to set when credential is read-only.

This property is used to get or set the certificate used to represent the service.

The following code shows how to use this method to get the certificate used in a service's credentials.

NetTcpBinding b = new NetTcpBinding();
b.Security.Mode = SecurityMode.Message;
Type c = typeof(ICalculator);
Uri a = new Uri("net.tcp://MyMachineName/tcpBase");
Uri[] baseAddresses = new Uri[] { a };
ServiceHost sh = new ServiceHost(typeof(MyService), baseAddresses);
sh.AddServiceEndpoint(c, b, "Aloha");
sh.Credentials.ServiceCertificate.SetCertificate(
 StoreLocation.LocalMachine,
 StoreName.My,
 X509FindType.FindByThumbprint,
 "af1f50b20cd413ed9cd00c315bbb6dc1c08da5e6");
sh.Open();
   X509Certificate2 cert = sh.Credentials.ServiceCertificate.Certificate;

.NET Framework
Available since 3.0
Return to top
Show: