다음을 통해 공유


NamedPipe Activation

이 샘플에서는 WAS(Windows Process Activation Service)를 사용하는 서비스를 호스팅하여 이름 파이프를 통해 통신하는 서비스를 활성화하는 방법을 보여 줍니다. 이 샘플은 Getting Started 샘플을 기반으로 하며 실행하려면 Windows Vista가 필요합니다.

참고

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

이 샘플은 WAS(Windows Process Activation Services)에 의해 활성화된 작업자 프로세스에서 호스팅되는 서비스 라이브러리(.dll) 및 클라이언트 콘솔 프로그램(.exe)으로 구성됩니다. 클라이언트 동작은 콘솔 창에 표시됩니다.

이 서비스는 요청-회신 통신 패턴을 정의하는 계약을 구현합니다. 계약은 다음 샘플 코드처럼 수학 연산(더하기, 빼기, 곱하기 및 나누기)을 노출시키는 ICalculator 인터페이스에서 정의됩니다.

[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
public interface ICalculator
{
    [OperationContract]
    double Add(double n1, double n2);
    [OperationContract]
    double Subtract(double n1, double n2);
    [OperationContract]
    double Multiply(double n1, double n2);
    [OperationContract]
    double Divide(double n1, double n2);
}

클라이언트에서는 지정된 수학 연산을 동기적으로 요청하고 서비스 구현에서는 계산을 통해 올바른 결과를 반환합니다.

// Service class that implements the service contract.
public class CalculatorService : ICalculator
{
    public double Add(double n1, double n2)
    {
        return n1 + n2;
    }
    public double Subtract(double n1, double n2)
    {
        return n1 - n2;
    }
    public double Multiply(double n1, double n2)
    {
        return n1 * n2;
    }
    public double Divide(double n1, double n2)
    {
        return n1 / n2;
    }
}

샘플에서는 보안 없이 수정된 netNamedPipeBinding 바인딩을 사용합니다. 바인딩은 클라이언트 및 서비스에 대한 구성 파일에 지정됩니다. 서비스의 바인딩 형식은 다음 샘플 구성과 같이 끝점 요소의 binding 특성에 지정됩니다.

보안이 설정된 명명된 파이프 바인딩을 사용하려면 서버의 보안 모드를 원하는 보안 설정으로 변경하고 클라이언트에서 svcutil.exe를 다시 실행하여 업데이트된 클라이언트 구성 파일을 가져옵니다.

<system.serviceModel>
        <services>
            <service name="Microsoft.ServiceModel.Samples.CalculatorService"
               behaviorConfiguration="CalculatorServiceBehavior">

        <!-- This endpoint is exposed at the base address provided by host: net.pipe://localhost/servicemodelsamples/service.svc  -->
        <endpoint address="" 
                  binding="netNamedPipeBinding"
                  bindingConfiguration="Binding1" 
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <!-- the mex endpoint is explosed at net.pipe://localhost/servicemodelsamples/service.svc/mex -->
        <endpoint address="mex"
                  binding="mexNamedPipeBinding"
                  contract="IMetadataExchange" />
      </service>
        </services>    
        <bindings>
            <netNamedPipeBinding>
                <binding name="Binding1" >
                    <security mode = "None">
                    </security>
                </binding >
            </netNamedPipeBinding>
        </bindings>

    <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
    <behaviors>
      <serviceBehaviors>
        <behavior name="CalculatorServiceBehavior">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

클라이언트의 끝점 정보는 다음 샘플 코드와 같이 구성됩니다.

<system.serviceModel>

    <client>
      <endpoint name=""
                          address="net.pipe://localhost/servicemodelsamples/service.svc" 
                          binding="netNamedPipeBinding" 
                          bindingConfiguration="Binding1" 
                          contract="Microsoft.ServiceModel.Samples.ICalculator" />
    </client>

    <bindings>

      <!--  Following is the expanded configuration section for a NetNamedPipeBinding.
            Each property is configured with the default value.   -->

      <netNamedPipeBinding>
        <binding name="Binding1" 
                         maxBufferSize="65536"
                         maxConnections="10">
          <security mode = "None">
          </security>
        </binding >

      </netNamedPipeBinding>
    </bindings>

  </system.serviceModel>

샘플을 실행하면 작업 요청 및 응답이 클라이언트 콘솔 창에 표시됩니다. 클라이언트를 종료하려면 클라이언트 창에서 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 샘플의 일회 설치 절차를 수행했는지 확인합니다.

    또한 HTTP가 아닌 WCF 활성화 구성 요소를 설치해야 합니다.

    1. 시작 메뉴에서 제어판을 선택합니다.
    2. 프로그램 및 기능을 선택합니다.
    3. Windows 구성 요소 사용/사용 안 함을 클릭합니다.
    4. Microsoft .NET Framework 3.0 노드를 확장하고 Windows Communication Foundation 비-HTTP 활성화 기능을 선택합니다.
  2. 명명된 파이프 활성화를 지원하도록 WAS(Windows Process Activation Service)를 구성합니다.

    편의를 위해 다음 두 단계는 샘플 디렉터리에 있는 AddNetPipeSiteBinding.cmd라는 배치 파일에서 구현합니다.

    1. net. pipe 활성화를 지원하려면 먼저 기본 웹 사이트를 net. pipe 프로토콜에 바인딩해야 합니다. 이 작업은 IIS 7.0 관리 도구 집합과 함께 설치되는 appcmd.exe를 사용하여 수행할 수 있습니다. 고급 관리자 명령 프롬프트에서 다음 명령을 실행합니다.

      %windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" 
      -+bindings.[protocol='net.pipe',bindingInformation='*']
      

      참고

      이 명령은 줄 바꿈 없이 한 줄로 입력해야 합니다.

      이 명령은 기본 웹 사이트에 net.pipe 사이트 바인딩을 추가합니다.

    2. 사이트 내의 모든 응용 프로그램에서 공통된 net.pipe 바인딩을 공유하지만 각 응용 프로그램에서 net.pipe 지원을 개별적으로 사용하도록 설정할 수 있습니다. /servicemodelsamples 응용 프로그램에서 net.pipe를 사용하도록 설정하려면 고급 명령 프롬프트에서 다음 명령을 실행합니다.

      %windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/servicemodelsamples" /enabledProtocols:http,net.pipe
      

      참고

      이 명령은 줄 바꿈 없이 한 줄로 입력해야 합니다.

      이 명령을 실행하면 https://localhost/servicemodelsamples와 net.tcp://localhost/servicemodelsamples를 모두 사용하여 /servicemodelsamples 응용 프로그램에 액세스할 수 있습니다.

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

  4. 이 샘플에 대해 추가한 net. pipe 사이트 바인딩을 제거합니다.

    편의를 위해 다음 두 단계는 샘플 디렉터리에 있는 RemoveNetPipeSiteBinding.cmd라는 배치 파일에서 구현합니다.

    1. 고급 명령 프롬프트 창에서 다음 명령을 실행하여 사용된 프로토콜 목록에서 net.tcp를 제거합니다.

      %windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/servicemodelsamples" /enabledProtocols:http
      

      참고

      이 명령은 줄 바꿈 없이 한 줄로 입력해야 합니다.

    2. 고급 명령 프롬프트에서 다음 명령을 실행하여 net.tcp 사이트 바인딩을 제거합니다.

      %windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" --bindings.[protocol='net.pipe',bindingInformation='*']
      

      참고

      이 명령은 줄 바꿈 없이 한 줄로 입력해야 합니다.

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