X509CertificateRecipientServiceCredential.SetCertificate Method (String)

 

Specifies the certificate to use for representing the service by specifying the subject distinguished name.

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

public void SetCertificate(
	string subjectName
)

Parameters

subjectName
Type: System.String

Subject distinguished name.

For more information on the subjectName parameter, see SubjectName.

The following code shows how to use this method to set a certificate for a service credential from a subject name.

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(
    "CN=Administrator,CN=Users,DC=johndoe,DC=nttest,DC=microsoft,DC=com");
sh.Open();

.NET Framework
Available since 3.0
Return to top
Show: