X509CertificateRecipientServiceCredential.SetCertificate Method (StoreLocation, StoreName, X509FindType, Object)

 
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.

Specifies the certificate to use for representing the service by specifying query parameters such as storeLocation, storeName, findType and findValue.

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

Public Sub SetCertificate (
	storeLocation As StoreLocation,
	storeName As StoreName,
	findType As X509FindType,
	findValue As Object
)

Parameters

storeLocation
Type: System.Security.Cryptography.X509Certificates.StoreLocation

The location of the certificate store the client uses to obtain the client certificate.

storeName
Type: System.Security.Cryptography.X509Certificates.StoreName

Specifies the name of the X.509 certificate store to open.

findType
Type: System.Security.Cryptography.X509Certificates.X509FindType

Defines the type of X.509 search to be executed.

findValue
Type: System.Object

The value to search for in the X.509 certificate store.

Values for storeLocation are included in the StoreLocation enumeration:

  • LocalMachine: the certificate store assigned to the local machine (default).

  • CurrentUser: the certificate store used by the current user.

If the client application is running under a system account, then the certificate is typically in LocalMachine. If the client application is running under a user account, then the certificate is typically in CurrentUser.

Values for storeName are included in the StoreName enumeration.

Values for findType are included in the X509FindType enumeration.

The most commonly used enumeration is FindBySubjectName, which does a case-insensitive search on the subject name of certificates in the specified store. This can be an imprecise search. If more than one certificate is returned then the first one matching the find is used to represent the client.

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

Dim b As New NetTcpBinding()
b.Security.Mode = SecurityMode.Message
Dim c As Type = GetType(ICalculator)
Dim a As New Uri("net.tcp://MyMachineName/tcpBase")
Dim baseAddresses() As Uri = { a }
Dim sh As New ServiceHost(GetType(MyService), baseAddresses)
sh.AddServiceEndpoint(c, b, "Aloha")
sh.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "af1f50b20cd413ed9cd00c315bbb6dc1c08da5e6")
sh.Open()

.NET Framework
Available since 3.0
Return to top
Show: