다음을 통해 공유


Multiple Endpoints

Multiple Endpoints 샘플은 서비스에서 여러 끝점을 구성하는 방법과 클라이언트에서 각 끝점과 통신하는 방법을 보여 줍니다. 이 샘플은 Getting Started 샘플을 기반으로 합니다. 서비스 구성은 ICalculator 계약을 지원하지만 각각 다른 바인딩을 사용하여 다른 주소에 있는 두 개의 끝점을 정의하기 위해 수정되었습니다. 클라이언트 구성과 코드는 두 서비스 끝점 모두와 통신하기 위해 수정되었습니다.

참고

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

서비스 Web.config 파일은 각각 동일한 ICalculator 계약을 지원하지만 다른 바인딩을 사용하여 다른 주소에 있는 두 개의 끝점을 정의하기 위해 수정되었습니다. 첫 번째 끝점은 basicHttpBinding 바인딩을 사용하여 기본 주소에 정의되고 보안은 사용되지 않습니다. 두 번째 끝점은 wsHttpBinding 바인딩을 사용하여 {baseaddress}/secure에 정의되고 Windows 인증과 함께 WS-Security를 사용하여 기본적으로 보안됩니다.

<service 
    name="Microsoft.ServiceModel.Samples.CalculatorService"
    behaviorConfiguration="CalculatorServiceBehavior">
  <!-- This endpoint is exposed at the base address provided by host:       https://localhost/servicemodelsamples/service.svc  -->
  <endpoint address=""
            binding="basicHttpBinding"
            contract="Microsoft.ServiceModel.Samples.ICalculator" />
  <!-- secure endpoint exposed at {base address}/secure:       https://localhost/servicemodelsamples/service.svc/secure -->
  <endpoint address="secure"
            binding="wsHttpBinding"
            contract="Microsoft.ServiceModel.Samples.ICalculator" />
  ...
</service>

두 끝점은 또한 클라이언트에서 구성됩니다. 이러한 끝점에 이름이 제공되므로 호출자는 원하는 끝점 이름을 클라이언트의 생성자에 전달할 수 있습니다.

<client>
  <!-- Passing "basic" into the constructor of the CalculatorClient       class selects this endpoint.-->
  <endpoint name="basic"
            address="https://localhost/servicemodelsamples/service.svc" 
            binding="basicHttpBinding" 
            contract="Microsoft.ServiceModel.Samples.ICalculator" />
  <!-- Passing "secure" into the constructor of the CalculatorClient       class selects this endpoint.-->
  <endpoint name="secure"
address="https://localhost/servicemodelsamples/service.svc/secure" 
            binding="wsHttpBinding" 
            contract="Microsoft.ServiceModel.Samples.ICalculator" />
</client>

다음 코드와 같이 클라이언트는 두 끝점을 모두 사용합니다.

static void Main()
{
    // Create a client to the basic endpoint configuration.
    CalculatorClient client = new CalculatorClient("basic");
    Console.WriteLine("Communicate with basic endpoint.");
    // call operations
    DoCalculations(client);

    // Close the client and release resources.
    client.Close();

    // Create a client to the secure endpoint configuration.
    client = new CalculatorClient("secure");
    Console.WriteLine("Communicate with secure endpoint.");
    // Call operations.
    DoCalculations(client);

    // Close the client and release resources.
    client.Close();

    Console.WriteLine();
    Console.WriteLine("Press <ENTER> to terminate client.");
    Console.ReadLine();
}

클라이언트를 실행하면 두 끝점과의 상호 작용이 표시됩니다.

Communicate with basic endpoint.
Add(100,15.99) = 115.99
Subtract(145,76.54) = 68.46
Multiply(9,81.25) = 731.25
Divide(22,7) = 3.14285714285714
Communicate with secure endpoint.
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 샘플의 일회 설치 절차를 수행했는지 확인합니다.

  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.