X509CertificateInitiatorClientCredential.SetCertificate Metod

Definition

Anger det certifikat som ska användas för att representera tjänsten.

Överlagringar

Name Description
SetCertificate(String, StoreLocation, StoreName)

Gör att du kan ange det certifikat som ska användas för att representera tjänsten genom att ange det unika ämnesnamnet.

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Gör att du kan ange det certifikat som ska användas för att representera klienten genom att ange frågeparametrar som storeLocation, storeNamefindType och findValue.

SetCertificate(String, StoreLocation, StoreName)

Gör att du kan ange det certifikat som ska användas för att representera tjänsten genom att ange det unika ämnesnamnet.

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)

Parametrar

subjectName
String

Ämnesskilt namn.

storeLocation
StoreLocation

Platsen för certifikatarkivet som tjänsten använder för att hämta tjänstcertifikatet.

storeName
StoreName

Anger namnet på X.509-certifikatarkivet som ska öppnas.

Exempel

Följande kod anger vilket certifikat som ska användas.

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

Kommentarer

Mer information om parametern SubjectNamefinns i subjectName .

Värden för storeLocation ingår i StoreLocation uppräkningen:

  • LocalMachine: certifikatarkivet som tilldelats den lokala datorn (standard).

  • CurrentUser: certifikatarkivet som används av den aktuella användaren.

Om klientprogrammet körs under ett systemkonto finns certifikatet vanligtvis i LocalMachine. Om klientprogrammet körs under ett användarkonto finns certifikatet vanligtvis i CurrentUser.

Värden för storeName ingår i StoreName uppräkningen.

Gäller för

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Gör att du kan ange det certifikat som ska användas för att representera klienten genom att ange frågeparametrar som storeLocation, storeNamefindType och 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)

Parametrar

storeLocation
StoreLocation

Platsen för certifikatarkivet som klienten använder för att hämta klientcertifikatet.

storeName
StoreName

Anger namnet på X.509-certifikatarkivet som ska öppnas.

findType
X509FindType

Definierar vilken typ av X.509-sökning som ska köras.

findValue
Object

Värdet att söka efter i X.509-certifikatarkivet.

Exempel

Följande kod anger vilket certifikat som ska användas.

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

Kommentarer

Värden för storeLocation ingår i StoreLocation uppräkningen:

  • LocalMachine: certifikatarkivet som tilldelats den lokala datorn (standard).

  • CurrentUser: certifikatarkivet som används av den aktuella användaren.

Om klientprogrammet körs under ett systemkonto finns certifikatet vanligtvis i LocalMachine. Om klientprogrammet körs under ett användarkonto finns certifikatet vanligtvis i CurrentUser.

Värden för storeName ingår i StoreName uppräkningen.

Värden för findType ingår i X509FindType uppräkningen.

Den vanligaste uppräkningen är FindBySubjectName, som gör en skiftlägeskänslig sökning på certifikatets ämnesnamn i det angivna arkivet. Detta kan vara en oprecis sökning. Om mer än ett certifikat returneras används den första som matchar sökningen för att representera klienten.

Gäller för