이 샘플에서는 ServiceModel Metadata 유틸리티 도구(Svcutil.exe)에서 생성한 형식화된 클라이언트로부터 정보를 가져오는 방법을 보여 줍니다. 이 샘플은 계산기 서비스를 구현하는 Getting Started 샘플을 기반으로 합니다. 이 샘플에서 클라이언트는 콘솔 응용 프로그램(.exe)이고 서비스는 IIS(인터넷 정보 서비스)를 통해 호스팅됩니다.
참고: |
|---|
| 이 샘플의 설치 절차 및 빌드 지침은 이 항목의 끝부분에 나와 있습니다. |
클라이언트의 Endpoint 속성을 사용하면 클라이언트가 통신 중인 서비스 끝점에 대한 정보(예: 주소, 바인딩 및 계약 정보)에 액세스할 수 있습니다. 클라이언트의 InnerChannel 속성은 IClientChannel의 인스턴스로서 기본 채널에 대한 정보(예: 상태, 세션 식별자)에 액세스할 수 있게 합니다.
// Create a client.
CalculatorClient client = new CalculatorClient();
...
Console.WriteLine("Client - endpoint: " + client.Endpoint.Address);
Console.WriteLine("Client - binding: " + client.Endpoint.Binding.Name);
Console.WriteLine("Client - contract: " + client.Endpoint.Contract.Name);
IClientChannel channel = client.InnerChannel;
Console.WriteLine("Client channel - state: " + channel.State);
Console.WriteLine("Client channel - session identifier: " + channel.SessionId);
//Closing the client gracefully closes the connection and cleans up resources.
client.Close();
샘플을 실행하면 작업 요청 및 응답이 클라이언트 콘솔 창에 표시됩니다. 클라이언트를 종료하려면 클라이언트 창에서 Enter 키를 누릅니다.
Add(100,15.99) = 115.99
Subtract(145,76.54) = 68.46
Multiply(9,81.25) = 731.25
Divide(22,7) = 3.14285714285714
Client - endpoint: https://localhost/servicemodelsamples/service.svc
Client - binding: WSHttpBinding
Client - contract: ICalculator
Client channel - state: Opened
Client channel - session identifier: urn:uuid:ae16fbc4-2964-4e87-9fb1-c5aa78fc567e
Press <ENTER> to terminate client.
샘플을 설치, 빌드 및 실행하려면
Windows Communication Foundation 샘플의 일회 설치 절차를 수행했는지 확인합니다.
C# 또는 Visual Basic .NET 버전의 솔루션을 빌드하려면 Windows Communication Foundation 샘플 빌드의 지침을 따릅니다.
단일 컴퓨터 또는 다중 컴퓨터 구성에서 샘플을 실행하려면 Running the Windows Communication Foundation Samples의 지침을 따릅니다.
참고: |
|---|
컴퓨터에 이 샘플이 이미 설치되어 있을 수도 있습니다. 계속하기 전에 다음(기본) 디렉터리를 확인하십시오.
<InstallDrive>:\WF_WCF_Samples
이 디렉터리가 없으면 Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4로 이동하여 WCF(Windows Communication Foundation) 및 WF 샘플을 모두 다운로드하십시오. 이 샘플은 다음 디렉터리에 있습니다.
<InstallDrive>:\WF_WCF_Samples\WCF\Basic\Client\TypedClient
|
참고:
참고: