NamedPipe 範例示範系netNamedPipeBinding結,該系結會在相同計算機上提供跨進程通訊。 命名管道無法跨計算機運作。 此範例是以 開始使用計算機 服務為基礎。
在此範例中,服務是自我託管的。 用戶端和服務都是主控台應用程式。
備註
此範例的安裝程式和建置指示位於本主題結尾。
系結是在客戶端和服務組態檔中指定。 繫結類型是在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.
要設定、建置和執行範例,請執行以下步驟:
請確定您已針對 Windows Communication Foundation 範例 執行One-Time 安裝程式。
若要建置解決方案的 C# 或 Visual Basic .NET 版本,請遵循建置 Windows Communication Foundation 範例 中中的指示。
若要在單一計算機設定中執行範例,請遵循 執行 Windows Communication Foundation 範例中的指示。