X509CertificateInitiatorClientCredential.SetCertificate Metoda

Definicja

Określa certyfikat, który ma być używany do reprezentowania usługi.

Przeciążenia

SetCertificate(String, StoreLocation, StoreName)

Umożliwia określenie certyfikatu do reprezentowania usługi przez określenie nazwy wyróżniającej podmiotu.

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Umożliwia określenie certyfikatu do reprezentowania klienta przez określenie parametrów zapytania, takich jak storeLocation, storeNamei findType findValue.

SetCertificate(String, StoreLocation, StoreName)

Umożliwia określenie certyfikatu do reprezentowania usługi przez określenie nazwy wyróżniającej podmiotu.

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)

Parametry

subjectName
String

Nazwa wyróżniająca podmiotu.

storeLocation
StoreLocation

Lokalizacja magazynu certyfikatów używana przez usługę do uzyskania certyfikatu usługi.

storeName
StoreName

Określa nazwę magazynu certyfikatów X.509 do otwarcia.

Przykłady

Poniższy kod określa certyfikat do użycia.

// 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);

Uwagi

Aby uzyskać więcej informacji na temat parametru subjectName , zobacz SubjectName.

Wartości dla storeLocation są uwzględniane w wyliczeniem StoreLocation :

  • LocalMachine: magazyn certyfikatów przypisany do komputera lokalnego (wartość domyślna).

  • CurrentUser: magazyn certyfikatów używany przez bieżącego użytkownika.

Jeśli aplikacja kliencka jest uruchomiona na koncie systemowym, certyfikat jest zazwyczaj w LocalMachinesystemie . Jeśli aplikacja kliencka jest uruchomiona na koncie użytkownika, certyfikat jest zazwyczaj w elemecie CurrentUser.

Wartości dla storeName są uwzględniane w wyliczeniem StoreName .

Dotyczy

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Umożliwia określenie certyfikatu do reprezentowania klienta przez określenie parametrów zapytania, takich jak storeLocation, storeNamei findType 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)

Parametry

storeLocation
StoreLocation

Lokalizacja magazynu certyfikatów używanego przez klienta do uzyskania certyfikatu klienta.

storeName
StoreName

Określa nazwę magazynu certyfikatów X.509 do otwarcia.

findType
X509FindType

Definiuje typ wyszukiwania X.509 do wykonania.

findValue
Object

Wartość do wyszukania w magazynie certyfikatów X.509.

Przykłady

Poniższy kod określa certyfikat do użycia.

// 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")

Uwagi

Wartości dla storeLocation są uwzględniane w wyliczeniem StoreLocation :

  • LocalMachine: magazyn certyfikatów przypisany do komputera lokalnego (wartość domyślna).

  • CurrentUser: magazyn certyfikatów używany przez bieżącego użytkownika.

Jeśli aplikacja kliencka jest uruchomiona na koncie systemowym, certyfikat jest zazwyczaj w LocalMachinesystemie . Jeśli aplikacja kliencka jest uruchomiona na koncie użytkownika, certyfikat jest zazwyczaj w elemecie CurrentUser.

Wartości dla storeName są uwzględniane w wyliczeniem StoreName .

Wartości dla findType są uwzględniane w wyliczeniem X509FindType .

Najczęściej używane wyliczenie to FindBySubjectName, co umożliwia wyszukiwanie bez uwzględniania wielkości liter w nazwie podmiotu certyfikatów w określonym magazynie. Może to być nieprecyzyjne wyszukiwanie. Jeśli zwracany jest więcej niż jeden certyfikat, pierwszy pasujący do znajdowania jest używany do reprezentowania klienta.

Dotyczy