다음을 통해 공유


방법: 채널 보안 자격 증명 지정

WCF(Windows Communication Foundation) 서비스 모니커를 사용하면 COM 애플리케이션에서 WCF 서비스를 호출할 수 있습니다. 대부분의 WCF 서비스에서는 클라이언트가 인증 및 권한 부여를 위한 자격 증명을 지정해야 합니다. WCF 클라이언트에서 WCF 서비스를 호출할 때 관리 코드 또는 애플리케이션 구성 파일에서 이러한 자격 증명을 지정할 수 있습니다. COM 애플리케이션에서 WCF 서비스를 호출할 때 IChannelCredentials 인터페이스를 사용하여 자격 증명을 지정할 수 있습니다. 이 항목에서는 IChannelCredentials 인터페이스를 사용하여 자격 증명을 지정하는 다양한 방식을 설명합니다.

참고 항목

IChannelCredentials는 IDispatch 기반 인터페이스이며 Visual Studio 환경에서는 IntelliSense 기능을 가져오지 않습니다.

이 문서에서는 메시지 보안 샘플에 정의된 WCF 서비스를 사용합니다.

클라이언트 인증서 지정

  1. Message Security 디렉터리에서 Setup.bat 파일을 실행하여 필요한 테스트 인증서를 만든 후 설치합니다.

  2. 메시지 보안 프로젝트를 엽니다.

  3. [ServiceBehavior(Namespace="http://Microsoft.ServiceModel.Samples")]ICalculator 인터페이스 정의에 추가합니다.

  4. bindingNamespace="http://Microsoft.ServiceModel.Samples"를 서비스에 대한 App.config에 있는 엔드포인트 태그에 추가합니다.

  5. 메시지 보안 샘플을 빌드하고 Service.exe를 실행합니다. 서비스의 URI(http://localhost:8000/ServiceModelSamples/Service)를 찾아 서비스가 작동하는지 확인합니다.

  6. Visual Basic 6.0을 열고 새 표준 .exe 파일을 만듭니다. 폼에 단추를 추가하고 단추를 두 번 클릭하여 다음 코드를 클릭 처리기에 추가합니다.

        monString = "service:mexAddress=http://localhost:8000/ServiceModelSamples/Service?wsdl"  
        monString = monString + ", address=http://localhost:8000/ServiceModelSamples/Service"  
        monString = monString + ", contract=ICalculator, contractNamespace=http://Microsoft.ServiceModel.Samples"  
        monString = monString + ", binding=BasicHttpBinding_ICalculator, bindingNamespace=http://Microsoft.ServiceModel.Samples"  
    
        Set monikerProxy = GetObject(monString)  
    
        'Set the Service Certificate.  
     monikerProxy.ChannelCredentials.SetServiceCertificateAuthentication "CurrentUser", "NoCheck", "PeerOrChainTrust"  
    monikerProxy.ChannelCredentials.SetDefaultServiceCertificateFromStore "CurrentUser", "TrustedPeople", "FindBySubjectName", "localhost"  
    
        'Set the Client Certificate.  
        monikerProxy.ChannelCredentials.SetClientCertificateFromStoreByName "CN=client.com", "CurrentUser", "My"  
        MsgBox monikerProxy.Add(3, 4)  
    
  7. Visual Basic 애플리케이션을 실행하고 결과를 확인합니다.

    Visual Basic 애플리케이션에 메시지 상자가 나타나며 Add(3, 4)를 호출한 결과가 표시됩니다. SetClientCertificateFromFile(String, String, String) 또는 SetClientCertificateFromStoreByName(String, String, String)SetClientCertificateFromStore(String, String, String, Object) 대신 사용하여 클라이언트 인증서를 설정할 수도 있습니다.

    monikerProxy.ChannelCredentials.SetClientCertificateFromFile "C:\MyClientCert.pfx", "password", "DefaultKeySet"  
    

참고 항목

이 호출이 작동하려면 클라이언트가 실행 중인 컴퓨터에서 클라이언트 인증서가 신뢰되어야 합니다.

참고 항목

모니커의 형식이 잘못되었거나 서비스를 사용할 수 없는 경우 GetObject에 대한 호출은 “잘못된 구문”이라는 오류를 반환합니다. 이 오류가 발생하면 사용 중인 모니커가 정확하고 서비스를 사용할 수 있는지 확인합니다.

사용자 이름 및 암호 지정

  1. wsHttpBinding을 사용하도록 Service App.config 파일을 수정합니다. 이 때 사용자 이름과 암호를 확인해야 합니다.

  2. clientCredentialType을 UserName으로 설정합니다.

  3. Visual Basic 6.0을 열고 새 표준 .exe 파일을 만듭니다. 폼에 단추를 추가하고 단추를 두 번 클릭하여 다음 코드를 클릭 처리기에 추가합니다.

    monString = "service:mexAddress=http://localhost:8000/ServiceModelSamples/Service?wsdl"  
    monString = monString + ", address=http://localhost:8000/ServiceModelSamples/Service"  
    monString = monString + ", contract=ICalculator, contractNamespace=http://Microsoft.ServiceModel.Samples"  
    monString = monString + ", binding=WSHttpBinding_ICalculator, bindingNamespace=http://Microsoft.ServiceModel.Samples"  
    
    Set monikerProxy = GetObject(monString)  
    
    monikerProxy.ChannelCredentials.SetServiceCertificateAuthentication "CurrentUser", "NoCheck", "PeerOrChainTrust"  
    monikerProxy.ChannelCredentials.SetUserNameCredential "username", "password"  
    
    MsgBox monikerProxy.Add(3, 4)  
    
  4. Visual Basic 애플리케이션을 실행하고 결과를 확인합니다. Visual Basic 애플리케이션에 메시지 상자가 나타나며 Add(3, 4)를 호출한 결과가 표시됩니다.

    참고 항목

    이 샘플의 서비스 모니커에 지정된 바인딩이 WSHttpBinding_ICalculator로 변경되었습니다. 또한 SetUserNameCredential(String, String)을 호출할 때 유효한 사용자 이름과 암호를 제공해야 합니다.

Windows 자격 증명 지정

  1. Service App.config 파일에서 clientCredentialType을 Windows로 설정합니다.

  2. Visual Basic 6.0을 열고 새 표준 .exe 파일을 만듭니다. 폼에 단추를 추가하고 단추를 두 번 클릭하여 다음 코드를 클릭 처리기에 추가합니다.

    monString = "service:mexAddress=http://localhost:8000/ServiceModelSamples/Service?wsdl"  
    monString = monString + ", address=http://localhost:8000/ServiceModelSamples/Service"  
    monString = monString + ", contract=ICalculator, contractNamespace=http://Microsoft.ServiceModel.Samples"  
    monString = monString + ", binding=WSHttpBinding_ICalculator, bindingNamespace=http://Microsoft.ServiceModel.Samples"  
    monString = monString + ", upnidentity=domain\userID"  
    
    Set monikerProxy = GetObject(monString)  
     monikerProxy.ChannelCredentials.SetWindowsCredential "domain", "userID", "password", 1, True  
    
    MsgBox monikerProxy.Add(3, 4)  
    
  3. Visual Basic 애플리케이션을 실행하고 결과를 확인합니다. Visual Basic 애플리케이션에 메시지 상자가 나타나며 Add(3, 4)를 호출한 결과가 표시됩니다.

    참고 항목

    "domain", "userID" 및 "password"를 유효한 값으로 바꿔야 합니다.

발급 토큰 지정

  1. 발급 토큰은 페더레이션 보안을 사용하는 애플리케이션에서만 사용됩니다. 페더레이션 보안에 대한 자세한 내용은 페더레이션 및 발급된 토큰페더레이션 샘플을 참조하세요.

    다음 Visual Basic 코드 예제에서는 SetIssuedToken(String, String, String) 메서드를 호출하는 방법을 보여 줍니다.

        monString = "service:mexAddress=http://localhost:8000/ServiceModelSamples/Service?wsdl"  
        monString = monString + ", address=http://localhost:8000/SomeService/Service"  
        monString = monString + ", contract=ICalculator, contractNamespace=http://SomeService.Samples"  
        monString = monString + ", binding=WSHttpBinding_ISomeContract, bindingNamespace=http://SomeService.Samples"  
    
        Set monikerProxy = GetObject(monString)  
    monikerProxy.SetIssuedToken("http://somemachine/sts", "bindingType", "binding")  
    

    이 메서드의 매개 변수에 대한 자세한 내용은 SetIssuedToken(String, String, String)을 참조하세요.

참고 항목