X509CertificateInitiatorClientCredential.SetCertificate Метод

Определение

Указывает сертификат, используемый для представления службы.

Перегрузки

Имя Описание
SetCertificate(String, StoreLocation, StoreName)

Позволяет указать сертификат, используемый для представления службы, указав различающееся имя субъекта.

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Позволяет указать сертификат, используемый для представления клиента, указав такие параметры запроса, как storeLocation, storeNamefindType и findValue.

SetCertificate(String, StoreLocation, StoreName)

Позволяет указать сертификат, используемый для представления службы, указав различающееся имя субъекта.

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)

Параметры

subjectName
String

Различающееся имя субъекта.

storeLocation
StoreLocation

Расположение хранилища сертификатов, который используется службой для получения сертификата службы.

storeName
StoreName

Указывает имя открытого хранилища сертификатов X.509.

Примеры

Следующий код указывает используемый сертификат.

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

Комментарии

Дополнительные сведения о параметре subjectName см. в разделе SubjectName.

Значения для storeLocation перечисления включаются:StoreLocation

  • LocalMachine: хранилище сертификатов, назначенное локальному компьютеру (по умолчанию).

  • CurrentUser: хранилище сертификатов, используемое текущим пользователем.

Если клиентское приложение выполняется под системной учетной записью, сертификат обычно находится в LocalMachine. Если клиентское приложение выполняется под учетной записью пользователя, сертификат обычно находится в CurrentUser.

Значения для storeName перечисления включены в перечисление StoreName .

Применяется к

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

Позволяет указать сертификат, используемый для представления клиента, указав такие параметры запроса, как storeLocation, storeNamefindType и 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)

Параметры

storeLocation
StoreLocation

Расположение хранилища сертификатов, который клиент использует для получения сертификата клиента.

storeName
StoreName

Указывает имя открытого хранилища сертификатов X.509.

findType
X509FindType

Определяет тип выполняемого поиска X.509.

findValue
Object

Значение для поиска в хранилище сертификатов X.509.

Примеры

Следующий код указывает используемый сертификат.

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

Комментарии

Значения для storeLocation перечисления включаются:StoreLocation

  • LocalMachine: хранилище сертификатов, назначенное локальному компьютеру (по умолчанию).

  • CurrentUser: хранилище сертификатов, используемое текущим пользователем.

Если клиентское приложение выполняется под системной учетной записью, сертификат обычно находится в LocalMachine. Если клиентское приложение выполняется под учетной записью пользователя, сертификат обычно находится в CurrentUser.

Значения для storeName перечисления включены в перечисление StoreName .

Значения для findType перечисления включены в перечисление X509FindType .

Наиболее часто используется перечисление FindBySubjectName, которое выполняет поиск без учета регистра в имени субъекта сертификатов в указанном хранилище. Это может быть непреднастойный поиск. Если возвращается несколько сертификатов, первый соответствующий поиск используется для представления клиента.

Применяется к