다음을 통해 공유


어드레싱

주소 지정 샘플은 엔드포인트 주소의 다양한 측면과 기능을 보여 줍니다. 샘플은 시작하기를 기반으로 합니다. 이 샘플에서는 서비스가 자체 호스팅됩니다. 서비스와 클라이언트는 모두 콘솔 애플리케이션입니다. 이 서비스는 상대 및 절대 엔드포인트 주소의 조합을 사용하여 여러 엔드포인트를 정의합니다.

비고

이 샘플에 대한 설치 절차 및 빌드 지침은 이 항목의 끝에 있습니다.

서비스 구성 파일은 기본 주소와 네 개의 엔드포인트를 지정합니다. 기본 주소는 다음 샘플 구성에 설명된 대로 서비스/호스트/baseAddresses에서 add 요소를 사용하여 지정됩니다.

<service name="Microsoft.ServiceModel.Samples.CalculatorService"
         behaviorConfiguration="CalculatorServiceBehavior">
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost:8000/ServiceModelSamples/service" />
    </baseAddresses>
  </host>
</service>

다음 샘플 구성에 표시된 첫 번째 엔드포인트 정의는 상대 주소를 지정합니다. 즉, 엔드포인트 주소는 URI 컴퍼지션 규칙에 따른 기준 주소와 상대 주소의 조합입니다.

<!-- Empty relative address specified:
     use the base address provided by the host. -->
<!-- The endpoint address is
     http://localhost:8000/ServiceModelSamples/service. -->
<endpoint address=""
          binding="wsHttpBinding"
          contract="Microsoft.ServiceModel.Samples.ICalculator" />

이 경우 상대 주소가 비어 있으므로(""), 엔드포인트 주소는 기본 주소와 동일합니다. 실제 엔드포인트 주소는 .입니다 http://localhost:8000/servicemodelsamples/service.

두 번째 엔드포인트 정의는 다음 샘플 구성과 같이 상대 주소도 지정합니다.

<!-- The relative address specified: use the base address -->
<!-- provided by the host + path. The endpoint address is -->
<!-- http://localhost:8000/servicemodelsamples/service/test. -->
<endpoint address="/test"
          binding="wsHttpBinding"
          contract="Microsoft.ServiceModel.Samples.ICalculator" />

상대 주소인 "test"가 기본 주소에 추가됩니다. 실제 엔드포인트 주소는 .입니다 http://localhost:8000/servicemodelsamples/service/test.

세 번째 엔드포인트 정의는 다음 샘플 구성과 같이 절대 주소를 지정합니다.

<endpoint address="http://localhost:8001/hello/servicemodelsamples"
          binding="wsHttpBinding"
          contract="Microsoft.ServiceModel.Samples.ICalculator" />

기본 주소는 주소에서 아무 역할도 하지 않습니다. 실제 엔드포인트 주소는 .입니다 http://localhost:8001/hello/servicemodelsamples.

네 번째 엔드포인트 주소는 절대 주소와 다른 전송 TCP를 지정합니다. 기본 주소는 주소에서 아무 역할도 하지 않습니다. 실제 엔드포인트 주소는 .입니다 net.tcp://localhost:9000/servicemodelsamples/service.

<!-- The absolute address specified, different transport: -->
<!-- use the specified address, and ignore the base address. -->
<!-- The endpoint address is -->
<!-- net.tcp://localhost:9000/servicemodelsamples/service. -->
<endpoint address=
          "net.tcp://localhost:9000/servicemodelsamples/service"
          binding="netTcpBinding"
          contract="Microsoft.ServiceModel.Samples.ICalculator" />

클라이언트는 4개의 서비스 엔드포인트 중 하나에만 액세스하지만 4개 모두 구성 파일에 정의됩니다. 클라이언트는 개체를 만들 때 엔드포인트를 CalculatorProxy 선택합니다. 구성 이름을 CalculatorEndpoint1 처음부터 CalculatorEndpoint4변경하여 각 엔드포인트를 연습할 수 있습니다.

샘플을 실행하면 서비스는 각 엔드포인트의 주소, 바인딩 이름 및 계약 이름을 열거합니다. MEX(메타데이터 교환) 엔드포인트는 ServiceHost의 관점에서 또 다른 엔드포인트이므로 목록에 표시됩니다.

Service endpoints:
Endpoint - address:  http://localhost:8000/ServiceModelSamples/service
           binding:  WSHttpBinding
           contract: ICalculator
Endpoint - address:  http://localhost:8000/ServiceModelSamples/service/test
           binding:  WSHttpBinding
           contract: ICalculator
Endpoint - address:  http://localhost:8001/hello/servicemodelsamples
           binding:  WSHttpBinding
           contract: ICalculator
Endpoint - address:  net.tcp://localhost:9000/servicemodelsamples/service
           binding:  NetTcpBinding
           contract: ICalculator
Endpoint - address:  http://localhost:8000/ServiceModelSamples/service/mex
           binding:  MetadataExchangeHttpBinding
           contract: IMetadataExchange

The service is ready.
Press <ENTER> to terminate service.

클라이언트를 실행하면 작업 요청 및 응답이 서비스 및 클라이언트 콘솔 창 모두에 표시됩니다. 각 콘솔 창에서 Enter 키를 눌러 서비스 및 클라이언트를 종료합니다.

Add(100,15.99) = 115.99
Subtract(145,76.54) = 68.46
Multiply(9,81.25) = 731.25
Divide(22,7) = 3.14285714285714

Press <ENTER> to terminate client.

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

  1. Windows Communication Foundation 샘플 에 대한One-Time 설정 절차를 수행했는지 확인합니다.

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

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

    비고

    Svcutil.exe 사용하여 이 샘플의 구성을 다시 생성하는 경우 클라이언트 구성의 엔드포인트 이름을 클라이언트 코드와 일치하도록 수정해야 합니다.