다음을 통해 공유


Message Security Windows

이 샘플에서는 Windows 인증과 함께 메시지 수준 보안을 사용하도록 WSHttpBinding 바인딩을 구성하는 방법을 보여 줍니다. 이 샘플은 Getting Started 샘플을 기반으로 합니다. 이 샘플에서 서비스는 IIS(인터넷 정보 서비스)에서 호스팅되고 클라이언트는 콘솔 응용 프로그램(.exe)입니다.

참고

이 샘플의 설치 절차 및 빌드 지침은 이 항목의 끝부분에 나와 있습니다.

wsHttpBinding Element에 대한 기본 보안 Windows 인증을 사용하는 메시지 보안입니다. 이 샘플의 구성 파일은 명시적으로 security Element in wsHttpBindingmode 특성을 Message로 설정하고 clientCredentialType 특성을 Windows로 설정합니다. 이러한 값은 이 바인딩의 기본값이지만 다음 샘플 구성에서와 같이 실제 사용을 보여 주기 위해 명시적으로 구성되었습니다.

<bindings>
    <wsHttpBinding>
        <binding name="Binding1">
            <security mode="Message">
                <message clientCredentialType="Windows"/>
            </security>
        </binding>
    </wsHttpBinding>
</bindings>

클라이언트 끝점 구성은 서비스 끝점의 절대 주소, 바인딩 및 계약으로 구성됩니다. 클라이언트 바인딩은 적절한 securityModeauthenticationMode를 사용하여 구성됩니다.

<configuration>
  <system.serviceModel>
    <client>
      <endpoint address=
              "https://localhost/servicemodelsamples/service.svc" 
              binding="wsHttpBinding" 
              bindingConfiguration="Binding1" 
              contract="Microsoft.ServiceModel.Samples.ICalculator" />
    </client>

    <bindings>
      <wsHttpBinding>
        <!-- 
        <!--The default security for the WSHttpBinding is-->
        <!--Message security using Windows authentication. -->
        <!--This configuration explicitly defines the security mode -->
        <!--as Message and the clientCredentialType as Windows  -->
        <!--for demonstration purposes. -->
        <binding name="Binding1">
          <security mode="Message">
            <message clientCredentialType="Windows"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

ServiceSecurityContext를 사용하여 호출자의 ID에 액세스하는 방법을 보여 주기 위해 서비스 소스 코드가 수정되었습니다.

public string GetCallerIdentity()
{
    // The Windows identity of the caller can be accessed on the ServiceSecurityContext.WindowsIdentity.
    return OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;
}

샘플을 실행하면 작업 요청 및 응답이 클라이언트 콘솔 창에 표시됩니다. GetCallerIdentity라는 첫 번째 메서드는 호출자 ID의 이름을 클라이언트에게 반환합니다. 클라이언트를 종료하려면 콘솔 창에서 Enter 키를 누릅니다.

샘플을 설치, 빌드 및 실행하려면

  1. Windows Communication Foundation 샘플의 일회 설치 절차를 수행했는지 확인합니다.

  2. C# 또는 Visual Basic .NET 버전의 솔루션을 빌드하려면 Windows Communication Foundation 샘플 빌드의 지침을 따릅니다.

  3. 단일 컴퓨터 또는 다중 컴퓨터 구성에서 샘플을 실행하려면 Windows Communication Foundation 샘플 실행의 지침을 따릅니다.

Send comments about this topic to Microsoft.
© 2007 Microsoft Corporation. All rights reserved.