X509CertificateInitiatorClientCredential.SetCertificate Método

Definición

Especifica el certificado que se utiliza para representar al servicio.

Sobrecargas

SetCertificate(String, StoreLocation, StoreName)

Le permite especificar el certificado que se utiliza para representar al servicio especificando el nombre distintivo (DN) del asunto.

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Le permite especificar el certificado que se va a utilizar para representar al cliente especificando parámetros de la consulta como storeLocation, storeName, findType y findValue.

SetCertificate(String, StoreLocation, StoreName)

Source:
X509CertificateInitiatorClientCredential.cs
Source:
X509CertificateInitiatorClientCredential.cs
Source:
X509CertificateInitiatorClientCredential.cs

Le permite especificar el certificado que se utiliza para representar al servicio especificando el nombre distintivo (DN) del asunto.

public:
 void SetCertificate(System::String ^ subjectName, System::Security::Cryptography::X509Certificates::StoreLocation storeLocation, System::Security::Cryptography::X509Certificates::StoreName storeName);
public void SetCertificate (string subjectName, System.Security.Cryptography.X509Certificates.StoreLocation storeLocation, System.Security.Cryptography.X509Certificates.StoreName storeName);
member this.SetCertificate : string * System.Security.Cryptography.X509Certificates.StoreLocation * System.Security.Cryptography.X509Certificates.StoreName -> unit
Public Sub SetCertificate (subjectName As String, storeLocation As StoreLocation, storeName As StoreName)

Parámetros

subjectName
String

Nombre distintivo del asunto.

storeLocation
StoreLocation

La ubicación del almacén de certificados que el servicio utiliza para obtener el certificado del servicio.

storeName
StoreName

Especifica el nombre del almacén del certificado X.509 que se va a abrir.

Ejemplos

El siguiente código especifica el certificado que se va a utilizar.

// 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(
    "CN=MyName, OU=MyOrgUnit, C=US",
    StoreLocation.CurrentUser,
    StoreName.TrustedPeople);

Comentarios

Para obtener más información sobre el parámetro subjectName, vea SubjectName.

Los valores para storeLocation están incluidos en la enumeración StoreLocation:

  • LocalMachine: el almacén de certificados asignado al equipo local (predeterminado).

  • CurrentUser: el almacén de certificados utilizado por el usuario actual.

Si la aplicación cliente se está ejecutando bajo una cuenta del sistema, entonces el certificado está normalmente en LocalMachine. Si la aplicación cliente se está ejecutando en una cuenta de usuario, entonces el certificado se encuentra normalmente en CurrentUser.

Los valores para storeName están incluidos en la enumeración StoreName.

Se aplica a

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Source:
X509CertificateInitiatorClientCredential.cs
Source:
X509CertificateInitiatorClientCredential.cs
Source:
X509CertificateInitiatorClientCredential.cs

Le permite especificar el certificado que se va a utilizar para representar al cliente especificando parámetros de la consulta como storeLocation, storeName, findType y findValue.

public:
 void SetCertificate(System::Security::Cryptography::X509Certificates::StoreLocation storeLocation, System::Security::Cryptography::X509Certificates::StoreName storeName, System::Security::Cryptography::X509Certificates::X509FindType findType, System::Object ^ findValue);
public void SetCertificate (System.Security.Cryptography.X509Certificates.StoreLocation storeLocation, System.Security.Cryptography.X509Certificates.StoreName storeName, System.Security.Cryptography.X509Certificates.X509FindType findType, object findValue);
member this.SetCertificate : System.Security.Cryptography.X509Certificates.StoreLocation * System.Security.Cryptography.X509Certificates.StoreName * System.Security.Cryptography.X509Certificates.X509FindType * obj -> unit
Public Sub SetCertificate (storeLocation As StoreLocation, storeName As StoreName, findType As X509FindType, findValue As Object)

Parámetros

storeLocation
StoreLocation

La ubicación del almacén de certificados que el cliente utiliza para obtener el certificado de cliente.

storeName
StoreName

Especifica el nombre del almacén del certificado X.509 que se va a abrir.

findType
X509FindType

Define el tipo de búsqueda de X.509 que se va a ejecutar.

findValue
Object

El valor que se va a buscar en el almacén de certificados X.509.

Ejemplos

El siguiente código especifica el certificado que se va a utilizar.

// 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");
' Create a WSHttpBinding and set its security properties. The
' security mode is Message, and the client is authenticated with 
' a certificate.
Dim ea As New EndpointAddress("http://contoso.com/")
Dim b As New WSHttpBinding()
b.Security.Mode = SecurityMode.Message
b.Security.Message.ClientCredentialType = MessageCredentialType.Certificate

' Create the client with the binding and EndpointAddress.
Dim cc As 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")

Comentarios

Los valores para storeLocation están incluidos en la enumeración StoreLocation:

  • LocalMachine: el almacén de certificados asignado al equipo local (predeterminado).

  • CurrentUser: el almacén de certificados utilizado por el usuario actual.

Si la aplicación cliente se está ejecutando bajo una cuenta del sistema, entonces el certificado está normalmente en LocalMachine. Si la aplicación cliente se está ejecutando en una cuenta de usuario, entonces el certificado se encuentra normalmente en CurrentUser.

Los valores para storeName están incluidos en la enumeración StoreName.

Los valores para findType están incluidos en la enumeración X509FindType.

La enumeración normalmente utilizada es FindBySubjectName, que hace una búsqueda sin distinción entre mayúsculas y minúsculas en el nombre del asunto de certificados en el almacén especificado. Ésta puede ser una búsqueda imprecisa. Si más de un certificado se devuelve, a continuación el primero que coincida con la búsqueda se utiliza para representar al cliente.

Se aplica a