定义一个针对计算机跨进程通信进行安全、可靠、优化的绑定。 默认情况下,它生成运行时通信堆栈,WS-ReliableMessaging 可靠性、传输安全性的传输安全性、消息传递的命名管道和二进制消息编码。
<配置>
<system.serviceModel>
<绑定>
<netNamedPipeBinding>
Syntax
<netNamedPipeBinding>
<binding closeTimeout="TimeSpan"
hostNameComparisonMode="StrongWildCard/Exact/WeakWildcard"
maxBufferPoolSize="Integer"
maxBufferSize="Integer"
maxConnections="Integer"
maxReceivedMessageSize="Integer"
name="String"
openTimeout="TimeSpan"
receiveTimeout="TimeSpan"
sendTimeout="TimeSpan"
transactionFlow="Boolean"
transactionProtocol="OleTransactions/WS-AtomicTransactionOctober2004"
transferMode="Buffered/Streamed/StreamedRequest/StreamedResponse">
<security mode="None/Transport">
<transport protectionLevel="None/Sign/EncryptAndSign" />
</security>
<readerQuotas maxArrayLength="Integer"
maxBytesPerRead="Integer"
maxDepth="Integer"
maxNameTableCharCount="Integer"
maxStringContentLength="Integer" />
</binding>
</netNamedPipeBinding>
特性和元素
以下部分介绍属性、子元素和父元素
特性
| Attribute | Description |
|---|---|
| closeTimeout | 一个 TimeSpan 值,该值指定为完成关闭作提供的时间间隔。 此值应大于或等于 Zero。 默认值为 00:01:00。 |
| hostNameComparisonMode | 指定用于分析 URI 的 HTTP 主机名比较模式。 此属性的类型 HostNameComparisonMode,指示主机名在 URI 上匹配时是否用于访问服务。 默认值为 StrongWildcard忽略匹配项中的主机名。 |
| maxBufferPoolSize | 一个整数,指定此绑定的最大缓冲池大小。 默认值为 524,288 字节(512 * 1024)。 Windows Communication Foundation(WCF)的许多部分都使用缓冲区。 每次使用缓冲区时创建和销毁缓冲区的成本高昂,缓冲区的垃圾回收也非常昂贵。 使用缓冲池,可以从池中获取缓冲区,使用它,并在完成后将其返回到池。 因此,可以避免创建和销毁缓冲区的开销。 |
| maxBufferSize | 一个正整数,指定用于在内存中存储消息的缓冲区的最大大小(以字节为单位)。 如果缓冲区已满,则多余的数据将保留在基础套接字中,直到缓冲区再次有空间。 此值不能小于 maxReceivedMessageSize 属性。 默认值为 65536。 有关详细信息,请参阅 MaxBufferSize。 |
| 最大连接数 | 一个整数,指定服务将创建/接受的最大出站和入站连接数。 传入和传出连接根据此属性指定的单独限制进行计数。 超出限制的入站连接将排队,直到超出限制的空间可用。 超出限制的出站连接将排队,直到超出限制的空间可用。 默认值是10。 |
| maxReceivedMessageSize | 一个正整数,指定可在配置有此绑定的通道上接收的最大消息大小(以字节为单位),包括标头。 超出此限制的消息发送方将收到 SOAP 错误。 接收方删除消息,并在跟踪日志中创建事件的条目。 默认值为 65536。 |
| 姓名 | 一个字符串,其中包含绑定的配置名称。 此值应是唯一的,因为它用作绑定的标识。 从 .NET Framework 4 开始,不需要绑定和行为才能具有名称。 有关默认配置和无名称绑定和行为的详细信息,请参阅 WCF 服务的 简化配置 和 简化配置。 |
| openTimeout | 一个 TimeSpan 值,该值指定为打开作完成提供的时间间隔。 此值应大于或等于 Zero。 默认值为 00:01:00。 |
| receiveTimeout | 一个 TimeSpan 值,该值指定为接收作完成提供的时间间隔。 此值应大于或等于 Zero。 默认值为 00:10:00。 |
| sendTimeout | 一个 TimeSpan 值,该值指定为要完成的发送作提供的时间间隔。 此值应大于或等于 Zero。 默认值为 00:01:00。 |
| transactionFlow | 一个布尔值,该值指定绑定是否支持流动 WS-Transactions。 默认值为 false。 |
| transactionProtocol | 指定要用于此绑定的事务协议。 有效值为 - OleTransactions - WS-AtomicTransactionOctober2004 默认值为 OleTransactions。 此属性的类型 TransactionProtocol为 . |
| transferMode | 一个 TransferMode 值,该值指定消息是缓冲还是流式传输,还是请求或响应。 |
子元素
| 元素 | Description |
|---|---|
| <安全> | 定义绑定的安全设置。 此元素的类型 NetNamedPipeBindingElement为 . |
| <readerQuotas> | 定义由使用此绑定配置的终结点可以处理的 SOAP 消息复杂性的约束。 此元素的类型 XmlDictionaryReaderQuotasElement为 . |
父元素
| 元素 | Description |
|---|---|
| <绑定> | 此元素包含标准绑定和自定义绑定的集合。 |
注解
默认情况下,生成 NetNamedPipeBinding 运行时通信堆栈,该堆栈使用传输安全性、用于消息传递的命名管道和二进制消息编码。 此绑定是适当的 Windows Communication Foundation (WCF) 系统提供的用于计算机通信的选择。 它还支持事务。
默认配置类似于提供的NetTcpBinding配置NetNamedPipeBinding,但更简单,因为 WCF 实现仅用于计算机使用,因此公开的功能较少。 最明显的区别是, securityMode 该设置仅提供 None 和 Transport 选项。 SOAP 安全支持不是包含的选项。 可以使用可选 securityMode 属性配置安全行为。
Example
以下示例演示 netNamedPipeBinding 绑定,该绑定在同一台计算机上提供跨进程通信。 命名管道不能跨计算机工作。
绑定在客户端和服务配置文件中指定。 绑定类型在元素的属性<endpoint>中binding指定。 如果要配置 netNamedPipeBinding 绑定并更改其某些设置,则必须定义绑定配置。 终结点必须使用属性按名称 bindingConfiguration 引用绑定配置。 在此示例中,绑定配置名为 Binding1。
<configuration>
<system.serviceModel>
<services>
<service name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/ServiceModelSamples/service" />
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: net.pipe://localhost/ServiceModelSamples/service -->
<endpoint address="net.pipe://localhost/ServiceModelSamples/service"
binding="netNamedPipeBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<netNamedPipeBinding>
<binding 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>
<!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>