NetNamedPipeBinding

此範例示範 netNamedPipeBinding 繫結,這會在相同電腦上提供跨處理序通訊。具名通道不會跨電腦作業。這個範例以使用者入門範例計算機服務為基礎。

在此範例中,服務會自我裝載。用戶端和服務都是主控台應用程式。

ms752247.note(zh-tw,VS.90).gif注意:
此範例的安裝程序與建置指示位於本主題的結尾。

用戶端和服務的組態檔中會指定繫結。繫結類型指定在 <endpoint> 項目的 binding 屬性中,如下列範例組態中所示:

<endpoint address="net.pipe://localhost/ServiceModelSamples/service"
          binding="netNamedPipeBinding"
          contract="Microsoft.ServiceModel.Samples.ICalculator" />

前一個範例說明如何設定端點,以使用 netNamedPipeBinding 繫結搭配預設值。如果您要設定 netNamedPipeBinding 繫結並變更其部分設定,則您必須定義繫結組態。端點必須使用 bindingConfiguration 屬性,按照名稱參考繫結組態。

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

在此範例中,繫結組態會命名為 Binding1,並且具有下列定義:

<bindings>
  <!-- 
        Following is the expanded configuration section for a NetNamedPipeBinding.
        Each property is configured with the default value.
     -->
  <netNamedPipeBinding>
    <binding name="Binding1" 
             closeTimeout="00:01:00"
             openTimeout="00:01:00" 
             receiveTimeout="00:10:00" 
             sendTimeout="00:01:00"
             transactionFlow="false" 
             transferMode="Buffered" 
             transactionProtocol="OleTransactions"
             hostNameComparisonMode="StrongWildcard" 
             maxBufferPoolSize="524288"
             maxBufferSize="65536" 
             maxConnections="10" 
             maxReceivedMessageSize="65536">
      <security mode="Transport">
        <transport protectionLevel="EncryptAndSign" />
      </security>
    </binding>
  </netNamedPipeBinding>
</bindings>

當您執行範例時,作業要求和回應會顯示在用戶端主控台視窗中。在用戶端視窗中按下 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 範例的單次安裝程序

  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.