定义一个既安全又可靠且针对计算机上跨进程通信进行了优化的绑定。Defines a binding that is secure, reliable, optimized for on-machine cross process communication. 默认情况下,此绑定生成一个运行时通信堆栈,该堆栈包含 WS-ReliableMessaging 以保证可靠性,包含传输安全机制以保证传递的安全性,包含命名管道以便进行消息传递,并且包含二进制消息编码机制。By default, it generates a runtime communication stack with WS-ReliableMessaging for reliability, transport security for transfer security, named pipes for message delivery, and binary message encoding.



  <binding closeTimeout="TimeSpan"
    <security mode="None/Transport">
      <transport protectionLevel="None/Sign/EncryptAndSign" />
    <readerQuotas maxArrayLength="Integer"
                  maxStringContentLength="Integer" />

特性和元素Attributes and Elements

以下几节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements


属性Attribute 说明Description
closeTimeoutcloseTimeout 一个 TimeSpan 值,指定为完成关闭操作提供的时间间隔。A TimeSpan value that specifies the interval of time provided for a close operation to complete. 此值应大于或等于 ZeroThis value should be greater than or equal to Zero. 默认值为 00:01:00。The default is 00:01:00.
hostNameComparisonModehostNameComparisonMode 指定用于分析 URI 的 HTTP 主机名比较模式。Specifies the HTTP hostname comparison mode used to parse URIs. 此属性的类型为 HostNameComparisonMode,指示在对 URI 进行匹配时,是否使用主机名来访问服务。This attribute is of type HostNameComparisonMode, which indicates whether the hostname is used to reach the service when matching on the URI. 默认值为 StrongWildcard,表示忽略匹配项中的主机名。The default value is StrongWildcard, which ignores the hostname in the match.
maxBufferPoolSizemaxBufferPoolSize 一个整数,指定此绑定的最大缓冲池大小。An integer that specifies the maximum buffer pool size for this binding. 默认值为 524,288 字节 (512 * 1024)。The default is 524,288 bytes (512 * 1024). Windows Communication Foundation (WCF) 的许多部件使用缓冲区。Many parts of Windows Communication Foundation (WCF) use buffers. 每次使用缓冲区时,创建和销毁它们都将占用大量资源,而缓冲区的垃圾回收过程也是如此。Creating and destroying buffers each time they are used is expensive, and garbage collection for buffers is also expensive. 利用缓冲池,可以从缓冲池中获得缓冲区,使用缓冲区,然后在完成工作后将其返回给缓冲池。With buffer pools, you can take a buffer from the pool, use it, and return it to the pool once you are done. 这样就避免了创建和销毁缓冲区的系统开销。Thus the overhead in creating and destroying buffers is avoided.
maxBufferSizemaxBufferSize 一个正整数,指定内存中用于存储消息的缓冲区的最大大小(字节)。A positive integer that specifies the maximum size, in bytes, of the buffer used to store messages in memory. 如果缓冲区已满,则多余的数据会保留在基础套接字中,直到缓冲区重新具有可用空间。If the buffer is full, excess data remains in the underlying socket until the buffer has room again. 该值不能小于 maxReceivedMessageSize 属性。This value cannot be less than maxReceivedMessageSize attribute. 默认值为 65536。The default is 65536. 有关详细信息,请参阅 MaxBufferSizeFor more information, see MaxBufferSize.
maxConnectionsmaxConnections 一个整数,指定服务将创建/接受的最大出站和入站连接数。An integer that specifies the maximum number of outbound and inbound connections the service will create/accept. 传入和传出连接分别根据此属性指定的限制进行计数。Incoming and outgoing connections are counted against a separate limit specified by this attribute.

超出此限制的入站连接需要排队,直到连接数低于限制值。Inbound connections in excess of the limit are queued until a space below the limit becomes available.

超出此限制的出站连接需要排队,直到连接数低于限制值。Outbound connections in excess of the limit are queued until a space below the limit becomes available.

默认值为 10。The default is 10.
maxReceivedMessageSizemaxReceivedMessageSize 一个正整数,指定采用此绑定配置的通道上可以接收的最大消息大小(字节),包括消息头。A positive integer that specifies the maximum message size, in bytes, including headers, that can be received on a channel configured with this binding. 如果消息超出此限制,则发送方将收到 SOAP 错误。The sender of a message exceeding this limit will receive a SOAP fault. 接收方将删除该消息,并在跟踪日志中创建事件项。The receiver drops the message and creates an entry of the event in the trace log. 默认值为 65536。The default is 65536.
namename 一个包含绑定的配置名称的字符串。A string that contains the configuration name of the binding. 因为此值用作绑定的标识,所以它应该是唯一的。This value should be unique because it is used as an identification for the binding. 从 .NET Framework 4 开始,绑定和行为不需要具有名称。Starting with .NET Framework 4, bindings and behaviors are not required to have a name. 有关默认配置和无值绑定和行为的详细信息,请参阅WCF 服务的简化配置和简化配置。For more information about default configuration and nameless bindings and behaviors, see Simplified Configuration and Simplified Configuration for WCF Services.
openTimeoutopenTimeout 一个 TimeSpan 值,指定为完成打开操作提供的时间间隔。A TimeSpan value that specifies the interval of time provided for an open operation to complete. 此值应大于或等于 ZeroThis value should be greater than or equal to Zero. 默认值为 00:01:00。The default is 00:01:00.
receiveTimeoutreceiveTimeout 一个 TimeSpan 值,指定为完成接收操作提供的时间间隔。A TimeSpan value that specifies the interval of time provided for a receive operation to complete. 此值应大于或等于 ZeroThis value should be greater than or equal to Zero. 默认值为 00:10:00。The default is 00:10:00.
sendTimeoutsendTimeout 一个 TimeSpan 值,指定为完成发送操作提供的时间间隔。A TimeSpan value that specifies the interval of time provided for a send operation to complete. 此值应大于或等于 ZeroThis value should be greater than or equal to Zero. 默认值为 00:01:00。The default is 00:01:00.
transactionFlowtransactionFlow 一个布尔值,指定绑定是否支持流动 WS-Transactions。A Boolean value that specifies whether the binding supports flowing WS-Transactions. 默认值为 falseThe default is false.
transactionProtocoltransactionProtocol 指定与此绑定一起使用的事务处理协议。Specifies the transaction protocol to be used with this binding. 有效值为Valid values are

-OleTransactions- OleTransactions
-AtomicTransactionOctober2004- WS-AtomicTransactionOctober2004

默认值为 OleTransactions。The default is OleTransactions. 此属性的类型为 TransactionProtocolThis attribute is of type TransactionProtocol.
transferModetransferMode 一个 TransferMode 值,指定为请求或响应对消息进行缓冲处理还是流式处理。A TransferMode value that specifies whether messages are buffered or streamed or a request or response.

子元素Child Elements

元素Element 说明Description
<security> 定义绑定的安全设置。Defines the security settings for the binding. 此元素的类型为 NetNamedPipeBindingElementThis element is of type NetNamedPipeBindingElement.
<readerQuotas> 定义可由采用此绑定配置的终结点进行处理的 SOAP 消息的复杂性约束。Defines the constraints on the complexity of SOAP messages that can be processed by endpoints configured with this binding. 此元素的类型为 XmlDictionaryReaderQuotasElementThis element is of type XmlDictionaryReaderQuotasElement.

父元素Parent Elements

元素Element 说明Description
<bindings> 此元素包含标准绑定和自定义绑定的集合。This element holds a collection of standard and custom bindings.


默认情况下,NetNamedPipeBinding 会生成一个运行时通信堆栈,该堆栈可使用传输安全、用于消息传递的命名管道和二进制消息编码。The NetNamedPipeBinding generates a run-time communication stack by default, which uses transport security, named pipes for message delivery, and a binary message encoding. 此绑定是 Windows Communication Foundation (WCF) 系统提供的一个相应选项,可用于计算机上的通信。This binding is an appropriate Windows Communication Foundation (WCF) system-provided choice for on-machine communication. 它还支持事务。It also supports transactions.

NetNamedPipeBinding 的默认配置与 NetTcpBinding 所提供的配置类似,但要简单一些,因为 WCF 实现仅计划在计算机上使用,因此公开的功能就更少。The default configuration for the NetNamedPipeBinding is similar to the configuration provided by the NetTcpBinding, but it is simpler because the WCF implementation is only meant for on-machine use and consequently there are fewer exposed features. 其中最显著的差异在于 securityMode 设置只提供 NoneTransport 选项。The most notable difference is that the securityMode setting only offers the None and Transport options. 不包括 SOAP 安全支持选项。SOAP security support is not an included option. 可以使用可选的 securityMode 属性配置安全行为。The security behavior is configurable using the optional securityMode attribute.


下面的示例演示在同一台计算机上提供跨进程通信的 netNamedPipeBinding 绑定。The following example demonstrates the netNamedPipeBinding binding, which provides cross-process communication on the same machine. 命名管道不能跨计算机工作。Named pipes do not work across machines.

绑定是在客户端和服务的配置文件中指定的。The binding is specified in the configuration files for the client and service. 绑定类型是在 binding 元素的 <endpoint> 属性中指定的。The binding type is specified in the binding attribute of the <endpoint> element. 如果要配置 netNamedPipeBinding 绑定并更改它的一些设置,则必须定义绑定配置。If you want to configure the netNamedPipeBinding binding and change some of its settings, you must define a binding configuration. 终结点必须使用 bindingConfiguration 属性按名称来引用绑定配置。The endpoint must reference the binding configuration by name with a bindingConfiguration attribute. 在此示例中,此绑定配置被命名为 Binding1。In this example, the binding configuration is named Binding1.

      <service name="Microsoft.ServiceModel.Samples.CalculatorService"
            <add baseAddress="http://localhost:8000/ServiceModelSamples/service" />
        <!-- this endpoint is exposed at the base address provided by host: net.pipe://localhost/ServiceModelSamples/service  -->
        <endpoint address="net.pipe://localhost/ServiceModelSamples/service"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->
        <endpoint address="mex"
                  contract="IMetadataExchange" />
        <binding closeTimeout="00:01:00"
          <security mode="Transport">
            <transport protectionLevel="EncryptAndSign" />
    <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
        <behavior name="CalculatorServiceBehavior">
          <serviceMetadata httpGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="False" />

请参阅See also