次の方法で共有


X509CertificateRecipientServiceCredential.SetCertificate メソッド

定義

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

オーバーロード

SetCertificate(String)

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

SetCertificate(String, StoreLocation, StoreName)

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

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

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

SetCertificate(String)

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

public:
 void SetCertificate(System::String ^ subjectName);
public void SetCertificate (string subjectName);
member this.SetCertificate : string -> unit
Public Sub SetCertificate (subjectName As String)

パラメーター

subjectName
String

サブジェクト識別名。

このメソッドを使用して、サブジェクト名からサービス資格情報の証明書を設定する方法を次のコードに示します。

NetTcpBinding b = new NetTcpBinding();
b.Security.Mode = SecurityMode.Message;
Type c = typeof(ICalculator);
Uri a = new Uri("net.tcp://MyMachineName/tcpBase");
Uri[] baseAddresses = new Uri[] { a };
ServiceHost sh = new ServiceHost(typeof(MyService), baseAddresses);
sh.AddServiceEndpoint(c, b, "Aloha");
sh.Credentials.ServiceCertificate.SetCertificate(
    "CN=Administrator,CN=Users,DC=johndoe,DC=nttest,DC=microsoft,DC=com");
sh.Open();
Dim b As New NetTcpBinding()
b.Security.Mode = SecurityMode.Message
Dim c As Type = GetType(ICalculator)
Dim a As New Uri("net.tcp://MyMachineName/tcpBase")
Dim baseAddresses() As Uri = { a }
Dim sh As New ServiceHost(GetType(MyService), baseAddresses)
sh.AddServiceEndpoint(c, b, "Aloha")
sh.Credentials.ServiceCertificate.SetCertificate("CN=Administrator,CN=Users,DC=johndoe,DC=nttest,DC=microsoft,DC=com")
sh.Open()

注釈

subjectName パラメーターの詳細については、「SubjectName」を参照してください。

適用対象

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 証明書ストアの名前を指定します。

このメソッドを使用してサービス資格情報の証明書を設定する方法を次のコードに示します。

NetTcpBinding b = new NetTcpBinding();
b.Security.Mode = SecurityMode.Message;
Type c = typeof(ICalculator);
Uri a = new Uri("net.tcp://MyMachineName/tcpBase");
Uri[] baseAddresses = new Uri[] { a };
ServiceHost sh = new ServiceHost(typeof(MyService), baseAddresses);
sh.AddServiceEndpoint(c, b, "Aloha");
sh.Credentials.ServiceCertificate.SetCertificate(
    "CN=Administrator,CN=Users,DC=johndoe,DC=nttest,DC=microsoft,DC=com",
    StoreLocation.LocalMachine,
    StoreName.My);
sh.Open();
Dim b As New NetTcpBinding()
b.Security.Mode = SecurityMode.Message
Dim c As Type = GetType(ICalculator)
Dim a As New Uri("net.tcp://MyMachineName/tcpBase")
Dim baseAddresses() As Uri = { a }
Dim sh As New ServiceHost(GetType(MyService), baseAddresses)
sh.AddServiceEndpoint(c, b, "Aloha")
sh.Credentials.ServiceCertificate.SetCertificate("CN=Administrator,CN=Users,DC=johndoe,DC=nttest,DC=microsoft,DC=com", StoreLocation.LocalMachine, StoreName.My)
sh.Open()

注釈

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 証明書ストアで検索する値。

このメソッドを使用してサービス資格情報の証明書を設定する方法を次のコードに示します。

    NetTcpBinding b = new NetTcpBinding();
    b.Security.Mode = SecurityMode.Message;
    Type c = typeof(ICalculator);
    Uri a = new Uri("net.tcp://MyMachineName/tcpBase");
    Uri[] baseAddresses = new Uri[] { a };
    ServiceHost sh = new ServiceHost(typeof(MyService), baseAddresses);
    sh.AddServiceEndpoint(c, b, "Aloha");
    sh.Credentials.ServiceCertificate.SetCertificate(
        StoreLocation.LocalMachine,
        StoreName.My,
        X509FindType.FindByThumbprint,
        "af1f50b20cd413ed9cd00c315bbb6dc1c08da5e6");
    sh.Open();
Dim b As New NetTcpBinding()
b.Security.Mode = SecurityMode.Message
Dim c As Type = GetType(ICalculator)
Dim a As New Uri("net.tcp://MyMachineName/tcpBase")
Dim baseAddresses() As Uri = { a }
Dim sh As New ServiceHost(GetType(MyService), baseAddresses)
sh.AddServiceEndpoint(c, b, "Aloha")
sh.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "af1f50b20cd413ed9cd00c315bbb6dc1c08da5e6")
sh.Open()

注釈

storeLocation の値は、StoreLocation 列挙体に格納されます。

  • LocalMachine: ローカル コンピューターに割り当てられた証明書ストア (既定値)。

  • CurrentUser: 現在のユーザーが使用している証明書ストア。

クライアント アプリケーションがシステム アカウントで実行されている場合、証明書は通常、LocalMachine にあります。 クライアント アプリケーションがユーザー アカウントで実行されている場合、証明書は通常、CurrentUser にあります。

storeName の値は、StoreName 列挙体に格納されます。

findType の値は、X509FindType 列挙体に格納されます。

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

適用対象