NamedPipe 示例演示netNamedPipeBinding
绑定,该绑定在同一台计算机上提供跨进程通信。 命名管道不能跨计算机工作。 此示例基于 入门 计算器服务。
在此示例中,该服务是自托管的。 客户端和服务都是控制台应用程序。
注释
本示例的设置过程和生成说明位于本主题末尾。
绑定在客户端和服务配置文件中指定。 绑定类型是在 > 或 > 元素的 属性中指定的,如下面的示例配置所示:
<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 示例中的说明进行操作。