X509CertificateInitiatorClientCredential.SetCertificate メソッド

定義

サービスを表すために使用する証明書を指定します。

オーバーロード

SetCertificate(String, StoreLocation, StoreName)

サブジェクト識別名を指定して、サービスを表すために使用する証明書を指定します。

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

storeLocationstoreNamefindTypefindValue などのクエリ パラメーターを指定して、クライアントを表すために使用する証明書を指定します。

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)

storeLocationstoreNamefindTypefindValue などのクエリ パラメーターを指定して、クライアントを表すために使用する証明書を指定します。

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 です。これは、指定されたストア内の証明書のサブジェクト名を検索 (大文字小文字の違いは無視) します。 この検索結果は厳密ではない可能性があります。 2 つ以上の証明書が返された場合は、最初に一致した証明書がクライアントを表すものとして使用されます。

適用対象