X509CertificateInitiatorClientCredential.SetCertificate Metoda

Definice

Určuje certifikát, který se má použít k reprezentaci služby.

Přetížení

SetCertificate(String, StoreLocation, StoreName)

Umožňuje určit certifikát, který se má použít k reprezentaci služby, zadáním rozlišujícího názvu předmětu.

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Umožňuje zadat certifikát, který se má použít k reprezentaci klienta, zadáním parametrů dotazu, jako storeLocationjsou , storeNamefindType a findValue.

SetCertificate(String, StoreLocation, StoreName)

Zdroj:
X509CertificateInitiatorClientCredential.cs
Zdroj:
X509CertificateInitiatorClientCredential.cs
Zdroj:
X509CertificateInitiatorClientCredential.cs

Umožňuje určit certifikát, který se má použít k reprezentaci služby, zadáním rozlišujícího názvu předmětu.

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

Rozlišující název subjektu.

storeLocation
StoreLocation

Umístění úložiště certifikátů, které služba používá k získání certifikátu služby.

storeName
StoreName

Určuje název úložiště certifikátů X.509, které se má otevřít.

Příklady

Následující kód určuje certifikát, který se má použít.

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

Poznámky

Další informace o parametru najdete v subjectName tématu SubjectName.

Hodnoty pro storeLocation jsou zahrnuty ve výčtu StoreLocation :

  • LocalMachine: úložiště certifikátů přiřazené k místnímu počítači (výchozí).

  • CurrentUser: úložiště certifikátů používané aktuálním uživatelem.

Pokud klientská aplikace běží pod systémovým účtem, pak je certifikát obvykle v LocalMachine. Pokud klientská aplikace běží pod uživatelským účtem, je certifikát obvykle v CurrentUser.

Hodnoty pro storeName jsou zahrnuty do výčtu StoreName .

Platí pro

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Zdroj:
X509CertificateInitiatorClientCredential.cs
Zdroj:
X509CertificateInitiatorClientCredential.cs
Zdroj:
X509CertificateInitiatorClientCredential.cs

Umožňuje zadat certifikát, který se má použít k reprezentaci klienta, zadáním parametrů dotazu, jako storeLocationjsou , storeNamefindType a 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

Umístění úložiště certifikátů, které klient používá k získání klientského certifikátu.

storeName
StoreName

Určuje název úložiště certifikátů X.509, které se má otevřít.

findType
X509FindType

Definuje typ vyhledávání X.509, který má být proveden.

findValue
Object

Hodnota, která se má vyhledat v úložišti certifikátů X.509.

Příklady

Následující kód určuje certifikát, který se má použít.

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

Poznámky

Hodnoty pro storeLocation jsou zahrnuty ve výčtu StoreLocation :

  • LocalMachine: úložiště certifikátů přiřazené k místnímu počítači (výchozí).

  • CurrentUser: úložiště certifikátů používané aktuálním uživatelem.

Pokud klientská aplikace běží pod systémovým účtem, pak je certifikát obvykle v LocalMachine. Pokud klientská aplikace běží pod uživatelským účtem, je certifikát obvykle v CurrentUser.

Hodnoty pro storeName jsou zahrnuty do výčtu StoreName .

Hodnoty pro findType jsou zahrnuty do výčtu X509FindType .

Nejčastěji používaný výčet je FindBySubjectName, který provádí vyhledávání bez rozlišování velkých a malých písmen v názvu subjektu certifikátů v zadaném úložišti. Může se jednat o nepřesné hledání. Pokud je vráceno více než jeden certifikát, použije se první certifikát odpovídající nalezený k reprezentaci klienta.

Platí pro