X509CertificateInitiatorClientCredential.SetCertificate Metodo

Definizione

Specifica il certificato da utilizzare per rappresentare il servizio.

Overload

SetCertificate(String, StoreLocation, StoreName)

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

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Consente di specificare il certificato da utilizzare per rappresentare il client specificando parametri delle query quali storeLocation, storeName, findType e findValue.

SetCertificate(String, StoreLocation, StoreName)

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

Consente di specificare il certificato da utilizzare 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 utilizzato dal servizio per ottenere il certificato del servizio.

storeName
StoreName

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

Esempio

Nell'esempio di codice seguente viene specificato il certificato da utilizzare.

// 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 ulteriori informazioni sul parametro subjectName, vedere SubjectName.

I valori del parametro storeLocation sono compresi nell'enumerazione StoreLocation:

  • LocalMachine: l'archivio certificati assegnato al computer locale (predefinito).

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

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

I valori del parametro storeName sono compresi 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 utilizzare per rappresentare il client specificando parametri delle query quali storeLocation, storeName, findType 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 utilizzato dal client per ottenere il certificato del 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

Nell'esempio di codice seguente viene specificato il certificato da utilizzare.

// 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 del parametro storeLocation sono compresi nell'enumerazione StoreLocation:

  • LocalMachine: l'archivio certificati assegnato al computer locale (predefinito).

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

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

I valori del parametro storeName sono compresi nell'enumerazione StoreName.

I valori del parametro findType sono compresi nell'enumerazione X509FindType.

L'enumerazione più comunemente usata è FindBySubjectName, che effettua una ricerca senza distinzione fra maiuscole e minuscole sul nome soggetto dei certificati nell'archivio specificato. Può trattarsi di una ricerca imprecisa. Se viene restituito più di un certificato, viene utilizzato il primo che corrisponde alla ricerca per rappresentare il client.

Si applica a