이 서비스는 WCF(Windows Communication Foundation)를 사용하여 클라이언트가 서비스에 인증되는 방법을 지정할 수 있습니다. 예를 들어 서비스는 클라이언트가 인증서로 인증되도록 규정할 수 있습니다.
클라이언트 자격 증명 유형을 확인하려면
서비스의 메타데이터 엔드포인트에서 메타데이터를 검색합니다. 메타데이터는 일반적으로 선택한 프로그래밍 언어의 클라이언트 코드(기본값은 Visual C#) 및 XML 구성 파일의 두 파일로 구성됩니다. 메타데이터를 검색하는 한 가지 방법은 Svcutil.exe 도구를 사용하여 클라이언트 코드 및 클라이언트 구성을 반환하는 것입니다. 자세한 내용은 메타데이터 검색 및 ServiceModel 메타데이터 유틸리티 도구(Svcutil.exe)를 참조하세요.
XML 구성 파일을 엽니다. Svcutil.exe 도구를 사용하는 경우 파일의 기본 이름은 Output.config.
보안 요소
. 여기서를 찾습니다 속성( 보안 모드 = )은 보안 모드 중 하나로 설정됩니다. 모드 값과 일치하는 자식 요소를 찾습니다. 예를 들어 모드가 Message로 설정된 경우 보안< 요소에><포함된 메시지> 요소를 찾습니다.
clientCredentialType속성에 할당된 값을 확인합니다. 실제 값은 사용되는 모드, 전송 또는 메시지에 따라 달라집니다.
다음 XML 코드는 메시지 보안을 사용하고 클라이언트를 인증하기 위해 인증서를 요구하는 클라이언트에 대한 구성을 보여줍니다.
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Certificate" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
예: 인증서를 클라이언트 자격 증명으로 사용하여 TCP 전송 모드
다음은 보안 모드를 전송 모드로 설정하고 클라이언트 자격 증명 값을 X.509 인증서로 설정하는 예제입니다. 다음 절차에서는 코드 및 구성에서 클라이언트의 클라이언트 자격 증명 값을 설정하는 방법을 보여 줍니다. ServiceModel 메타데이터 유틸리티 도구(Svcutil.exe)를 사용하여 서비스에서 메타데이터(코드 및 구성)를 반환한 것으로 가정합니다. 자세한 내용은 방법: 클라이언트 만들기를 참조하세요.
코드에서 클라이언트에 클라이언트 자격 증명 값을 지정하려면
ServiceModel 메타데이터 유틸리티 도구(Svcutil.exe)를 사용하여 서비스에서 코드 및 구성을 생성합니다.
생성된 코드를 사용하여 WCF 클라이언트의 인스턴스를 만듭니다.
클라이언트 클래스에서 클래스의 ClientCredentialsClientBase<TChannel> 속성을 적절한 값으로 설정합니다. 다음은 X509CertificateInitiatorClientCredential 클래스의 SetCertificate 메서드를 사용하여 속성을 X.509 인증서로 설정하는 예제입니다.
// Create a binding using Transport and a certificate. NetTcpBinding b = new NetTcpBinding(); b.Security.Mode = SecurityMode.Transport; b.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate; // Create an EndPointAddress. EndpointAddress ea = new EndpointAddress( "net.tcp://localHost:8036/Calculator/MyCalculator"); // Create the client. CalculatorClient cc = new CalculatorClient(b, ea); // Set the certificate for the client. cc.ClientCredentials.ClientCertificate.SetCertificate( StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "cohowinery.com"); try { cc.Open(); // Begin using the client. Console.WriteLine(cc.Divide(1001, 2)); cc.Close(); } catch (AddressAccessDeniedException adExc) { Console.WriteLine(adExc.Message); Console.ReadLine(); } catch (System.Exception exc) { Console.WriteLine(exc.Message); Console.ReadLine(); }' Create a binding using Transport and a certificate. Dim b As New NetTcpBinding() b.Security.Mode = SecurityMode.Transport b.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate ' Create an EndPointAddress. Dim ea As New EndpointAddress("net.tcp://localHost:8036/Calculator/MyCalculator") ' Create the client. Dim cc As New CalculatorClient(b, ea) ' Set the certificate for the client. cc.ClientCredentials.ClientCertificate.SetCertificate( _ StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "cohowinery.com") Try cc.Open() ' Begin using the client. Console.WriteLine(cc.Divide(1001, 2)) cc.Close() Catch adExc As AddressAccessDeniedException Console.WriteLine(adExc.Message) Console.ReadLine() Catch exc As System.Exception Console.WriteLine(exc.Message) Console.ReadLine() End TryX509FindType 클래스의 모든 열거형을 사용할 수 있습니다. 인증서가 변경되는 경우(만료 날짜로 인해) 여기서 주체 이름이 사용됩니다. 주체 이름을 사용하면 인프라에서 인증서를 다시 찾을 수 있습니다.
구성에서 클라이언트의 클라이언트 자격 증명 값을 지정하려면
<behavior> 요소를 <behaviors> 요소에 추가합니다.
동작 요소에 <clientCredentials> 요소를 <추가합니다> . 필요한
name특성을 적절한 값으로 설정해야 합니다.다음 코드와 같이 다음 특성을 적절한 값
storeLocation으로storeNamex509FindTypefindValue설정합니다. 인증서에 대한 자세한 내용은 인증서 작업을 참조하세요.<behaviors> <endpointBehaviors> <behavior name="endpointCredentialBehavior"> <clientCredentials> <clientCertificate findValue="Contoso.com" storeLocation="LocalMachine" storeName="TrustedPeople" x509FindType="FindBySubjectName" /> </clientCredentials> </behavior> </endpointBehaviors> </behaviors>클라이언트를 구성할 때 다음 코드와 같이 요소의
behaviorConfiguration특성을 설정<endpoint>하여 동작을 지정합니다. 엔드포인트 요소는 클라이언트< 요소의> 자식입니다. 또한bindingConfiguration특성을 클라이언트의 바인딩으로 설정하여 바인딩 구성의 이름을 지정합니다. 생성된 구성 파일을 사용하는 경우 바인딩의 이름이 자동으로 생성됩니다. 이 예제에서는 이름이"tcpBindingWithCredential"입니다.<client> <endpoint name ="" address="net.tcp://contoso.com:8036/aloha" binding="netTcpBinding" bindingConfiguration="tcpBindingWithCredential" behaviorConfiguration="endpointCredentialBehavior" /> </client>