다음을 통해 공유


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

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

ms735113.note(ko-kr,VS.100).gif참고:
IChannelCredentials는 IDispatch 기반 인터페이스이며 Visual Studio 환경에서는 IntelliSense 기능을 가져오지 않습니다.

이 기사에서는 Message Security 샘플에 정의된 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를 실행합니다. Internet Explorer를 사용하여 서비스의 URI(https://localhost:8000/ServiceModelSamples/Service)를 찾은 다음 서비스가 작동하는지 확인합니다.

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

        monString = "service:mexAddress=https://localhost:8000/ServiceModelSamples/Service?wsdl"
        monString = monString + ", address=https://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 또는 SetClientCertificateFromStoreByNameSetClientCertificateFromStore 대신 사용하여 클라이언트 인증서를 설정할 수도 있습니다.

    monikerProxy.ChannelCredentials.SetClientCertificateFromFile "C:\MyClientCert.pfx", "password", "DefaultKeySet"
    
ms735113.note(ko-kr,VS.100).gif참고:
이 호출이 작동하려면 클라이언트가 실행 중인 컴퓨터에서 클라이언트 인증서가 신뢰되어야 합니다.

ms735113.note(ko-kr,VS.100).gif참고:
모니커의 형식이 잘못되었거나 서비스를 사용할 수 없는 경우 GetObject를 호출하면 "구문이 잘못되었습니다."라는 오류가 반환됩니다. 이 오류가 발생하면 사용하고 있는 모니커가 올바르고 서비스를 사용할 수 있는지 확인하십시오.

사용자 이름 및 암호 지정

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

    <endpoint address=""
              binding="wsHttpBinding"
              bindingNamespace="http://Microsoft.ServiceModel.Samples" 
              bindingConfiguration="Binding1" 
              contract="Microsoft.ServiceModel.Samples.ICalculator" />
    
  2. clientCredentialType을 UserName으로 설정합니다.

    <bindings>
      <wsHttpBinding>
        <binding name="Binding1" >
          <security mode="Message">
             <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    
  3. Visual Basic 6.0을 열고 새 표준 .exe 파일을 만듭니다. 폼에 단추를 추가하고 단추를 두 번 클릭하여 다음 코드를 클릭 처리기에 추가합니다.

        monString = "service:mexAddress=https://localhost:8000/ServiceModelSamples/Service?wsdl"
        monString = monString + ", address=https://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)를 호출한 결과가 표시됩니다.

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

Windows 자격 증명 지정

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

    <bindings>
      <wsHttpBinding>
        <binding name="Binding1" >
          <security mode="Message">
            <message clientCredentialType="Windows"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    
  2. Visual Basic 6.0을 열고 새 표준 .exe 파일을 만듭니다. 폼에 단추를 추가하고 단추를 두 번 클릭하여 다음 코드를 클릭 처리기에 추가합니다.

        monString = "service:mexAddress=https://localhost:8000/ServiceModelSamples/Service?wsdl"
        monString = monString + ", address=https://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)를 호출한 결과가 표시됩니다.

    ms735113.note(ko-kr,VS.100).gif참고:
    "domain", "userID" 및 "password"를 유효한 값으로 바꿔야 합니다.

발급 토큰 지정

  1. 발급 토큰은 페더레이션 보안을 사용하는 응용 프로그램에서만 사용됩니다. 페더레이션 보안에 대한 자세한 내용은 페더레이션 및 발급된 토큰Federation 샘플을 참조하십시오.

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

        monString = "service:mexAddress=https://localhost:8000/ServiceModelSamples/Service?wsdl"
        monString = monString + ", address=https://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을 참조하십시오.

참고 항목

작업

방법: 페더레이션 서비스에서 자격 증명 구성
방법: 페더레이션 클라이언트 만들기

개념

페더레이션
WCF의 메시지 보안
바인딩 및 보안