This documentation is archived and is not being maintained.

X509CertificateRecipientServiceCredential.Certificate Property

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.

ExceptionCondition
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

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: