Condividi tramite


X509CertificateInitiatorClientCredential.SetCertificate Metodo

Definizione

Specifica il certificato da utilizzare per rappresentare il servizio.

Overload

Nome Descrizione
SetCertificate(String, StoreLocation, StoreName)

Consente di specificare il certificato da usare per rappresentare il servizio specificando il nome distinto del soggetto.

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Consente di specificare il certificato da usare per rappresentare il client specificando parametri di query come storeLocation, storeNamefindType e findValue.

SetCertificate(String, StoreLocation, StoreName)

Origine:
X509CertificateInitiatorClientCredential.cs
Origine:
X509CertificateInitiatorClientCredential.cs
Origine:
X509CertificateInitiatorClientCredential.cs

Consente di specificare il certificato da usare per rappresentare il servizio specificando il nome distinto del soggetto.

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)

Parametri

subjectName
String

Nome distinto del soggetto.

storeLocation
StoreLocation

Percorso dell'archivio certificati usato dal servizio per ottenere il certificato del servizio.

storeName
StoreName

Specifica il nome dell'archivio certificati X.509 da aprire.

Esempio

Il codice seguente specifica il certificato da usare.

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

Commenti

Per altre informazioni sul subjectName parametro , vedere SubjectName.

I valori per storeLocation sono inclusi nell'enumerazione StoreLocation :

  • LocalMachine: archivio certificati assegnato al computer locale (impostazione predefinita).

  • CurrentUser: l'archivio certificati usato dall'utente corrente.

Se l'applicazione client è in esecuzione con un account di sistema, il certificato è in genere in LocalMachine. Se l'applicazione client è in esecuzione con un account utente, il certificato è in genere in CurrentUser.

I valori per storeName sono inclusi nell'enumerazione StoreName .

Si applica a

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Origine:
X509CertificateInitiatorClientCredential.cs
Origine:
X509CertificateInitiatorClientCredential.cs
Origine:
X509CertificateInitiatorClientCredential.cs

Consente di specificare il certificato da usare per rappresentare il client specificando parametri di query come storeLocation, storeNamefindType e 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)

Parametri

storeLocation
StoreLocation

Percorso dell'archivio certificati usato dal client per ottenere il certificato client.

storeName
StoreName

Specifica il nome dell'archivio certificati X.509 da aprire.

findType
X509FindType

Definisce il tipo di ricerca X.509 da eseguire.

findValue
Object

Valore da cercare nell'archivio certificati X.509.

Esempio

Il codice seguente specifica il certificato da usare.

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

Commenti

I valori per storeLocation sono inclusi nell'enumerazione StoreLocation :

  • LocalMachine: archivio certificati assegnato al computer locale (impostazione predefinita).

  • CurrentUser: l'archivio certificati usato dall'utente corrente.

Se l'applicazione client è in esecuzione con un account di sistema, il certificato è in genere in LocalMachine. Se l'applicazione client è in esecuzione con un account utente, il certificato è in genere in CurrentUser.

I valori per storeName sono inclusi nell'enumerazione StoreName .

I valori per findType sono inclusi nell'enumerazione X509FindType .

L'enumerazione più comunemente usata è FindBySubjectName, che esegue una ricerca senza distinzione tra maiuscole e minuscole sul nome soggetto dei certificati nell'archivio specificato. Può trattarsi di una ricerca imprecisa. Se vengono restituiti più certificati, viene usato il primo corrispondente alla ricerca per rappresentare il client.

Si applica a