이 샘플에서는 Windows 인증에서 WSHttpBinding 메시지 수준 보안을 사용하도록 바인딩을 구성하는 방법을 보여 줍니다. 이 샘플은 시작 안내에 기반으로 합니다. 이 샘플에서 서비스는 IIS(인터넷 정보 서비스)에서 호스트되고 클라이언트는 콘솔 애플리케이션(.exe)입니다.
비고
이 샘플에 대한 설치 절차 및 빌드 지침은 이 항목의 끝에 있습니다.
wsHttpBinding의< 기본 보안은 Windows 인증을> 사용하는 메시지 보안입니다. 이 샘플의 mode에서 < 속성을 >로 설정하고, 속성을 Message로 명시적으로 설정합니다. 이러한 값은 이 바인딩의 기본값이지만 다음 샘플 구성에 표시된 것처럼 명시적으로 구성되어 해당 사용 방법을 보여 줍니다.
<bindings>
<wsHttpBinding>
<binding>
<security mode="Message">
<message clientCredentialType="Windows"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
클라이언트 엔드포인트 구성은 서비스 엔드포인트, 바인딩 및 계약에 대한 절대 주소로 구성됩니다. 클라이언트 바인딩은 적절한 securityMode 및 authenticationMode로 구성됩니다.
<system.serviceModel>
<client>
<endpoint address=
"http://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>
서비스 소스 코드는 호출자의 ID에 ServiceSecurityContext 액세스하는 데 사용할 수 있는 방법을 보여 주도록 수정되었습니다.
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 키를 눌러 클라이언트를 종료합니다.
샘플을 설정, 빌드 및 실행하려면
Windows Communication Foundation 샘플 에 대한One-Time 설정 절차를 수행했는지 확인합니다.
솔루션의 C# 또는 Visual Basic .NET 버전을 빌드하려면 Windows Communication Foundation 샘플빌드의 지침을 따릅니다.
단일 또는 컴퓨터 간 구성에서 샘플을 실행하려면 Windows Communication Foundation 샘플 실행의 지침을 따릅니다.