다음을 통해 공유


X509CertificateRecipientServiceCredential.SetCertificate 메서드

정의

서비스를 나타내는 데 사용할 인증서를 지정합니다.

오버로드

SetCertificate(String)

주체 고유 이름을 지정하여 서비스를 나타내는 데 사용할 인증서를 지정합니다.

SetCertificate(String, StoreLocation, StoreName)

주체 고유 이름, 인증서 저장소 이름 및 저장소 위치를 지정하여 서비스를 나타내는 데 사용할 인증서를 지정합니다.

SetCertificate(StoreLocation, StoreName, X509FindType, Object)

storeLocation, storeName, findTypefindValue와 같은 쿼리 매개 변수를 지정하여 서비스를 나타내기 위해 사용할 인증서를 지정합니다.

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)

storeLocation, storeName, findTypefindValue와 같은 쿼리 매개 변수를 지정하여 서비스를 나타내기 위해 사용할 인증서를 지정합니다.

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입니다. 검색이 정확하지 않을 수 있습니다. 둘 이상의 인증서가 반환될 경우 찾은 항목과 일치하는 첫 번째 항목이 클라이언트를 나타내는 데 사용됩니다.

적용 대상