Export (0) Print
Expand All

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

Allows you to specify the certificate to use to represent the client by specifying query parameters such as storeLocation, storeName, findType and findValue.

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

public void SetCertificate (
	StoreLocation storeLocation,
	StoreName storeName,
	X509FindType findType,
	Object findValue
)
public void SetCertificate (
	StoreLocation storeLocation, 
	StoreName storeName, 
	X509FindType findType, 
	Object findValue
)
public function SetCertificate (
	storeLocation : StoreLocation, 
	storeName : StoreName, 
	findType : X509FindType, 
	findValue : Object
)
Not applicable.

Parameters

storeLocation

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

storeName

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

findType

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

findValue

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 specifies the certificate to use.

// Create a WSHttpBinding and set its security properties. The
// security mode is Message, and the client is authenticated with 
// a certificate.
EndpointAddress ea = new EndpointAddress("http://contoso.com/");
WSHttpBinding b = new WSHttpBinding();
b.Security.Mode = SecurityMode.Message;
b.Security.Message.ClientCredentialType =
    MessageCredentialType.Certificate;

// Create the client with the binding and EndpointAddress.
CalculatorClient cc = new CalculatorClient(b, ea);

// Set the client credential value to a valid certificate.
cc.ClientCredentials.ClientCertificate.SetCertificate(
    StoreLocation.CurrentUser,
    StoreName.TrustedPeople,
    X509FindType.FindBySubjectName,
    "client.com");

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft