共用方式為


<netTcpBinding>

Specifies a secure, reliable, optimized binding suitable for cross-machine communication. By default, it generates a runtime communication stack with WS-ReliableMessaging for reliability, Windows Security for message security and authentication, TCP for message delivery, and binary message encoding.

<system.serviceModel>

  <bindings>

    <netTcpBinding>

                                    
                                    <netTcpBinding>
                                
                                    
                                       <binding 
                                
                                    
                                          closeTimeout="TimeSpan"
                                
                                    
                                          hostNameComparisonMode="StrongWildCard/Exact/WeakWildcard"
                                
                                    
                                          listenBacklog="Integer"
                                
                                    
                                          maxBufferPoolSize="integer"
                                
                                    
                                          maxBufferSize="Integer"
                                
                                    
                                          maxConnections="Integer" 
                                
                                    
                                          maxReceivedMessageSize="Integer"
                                
                                    
                                              
                                    
                                          name="string"
                                
                                    
                                          openTimeout="TimeSpan"
                                
                                    
                                          portSharingEnabled="Boolean"
                                
                                    
                                          receiveTimeout="TimeSpan"
                                
                                    
                                          sendTimeout="TimeSpan"
                                
                                    
                                          transactionFlow="Boolean" 
                                
                                    
                                          transactionProtocol="OleTransactions/WSAtomicTransactionOctober2004" 
                                
                                    
                                              
                                    
                                          transferMode="Buffered/Streamed/StreamedRequest/StreamedResponse"
                                
                                    
                                        
                                    
                                    
                                
                                    
                                          <reliableSession ordered="Boolean"
                                
                                    
                                                inactivityTimeout="TimeSpan"
                                
                                    
                                                enabled="Boolean" />
                                
                                    
                                          <security mode="None/Transport/Message/Both">
                                
                                    
                                                <message clientCredentialType="None/Windows/UserName/Certificate/InfoCard"
                                
                                    
                                                    defaultProtectionLevel="none/sign/EncryptAndSign" 
                                
                                    
                                                    algorithmSuite="Aes128/Aes192/Aes256/Rsa15Aes128/Rsa15Aes256" />
                                
                                    
                                                <transport clientCredentialType="None/Windows/Certificate"
                                
                                    
                                                    protectionLevel="None/Sign/EncryptAndSign" />
                                
                                    
                                          </security>
                                
                                    
                                           <readerQuotas maxDepth="integer" 
                                
                                    
                                                maxStringContentLength="integer"
                                
                                    
                                                maxByteArrayContentLength="integer"
                                
                                    
                                                maxBytesPerRead="integer"
                                
                                    
                                                maxNameTableCharCount="integer" />
                                
                                    
                                       </binding>
                                
                                    
                                    </netTcpBinding>
                                

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute Description

closeTimeout

A TimeSpan value that specifies the interval of time provided for a close operation to complete. This value should be greater than or equal to Zero. The default is 00:01:00.

hostnameComparisonMode

Specifies the HTTP hostname comparison mode used to parse URIs. This attribute is of type HostnameComparisonMode, which indicates whether the hostname is used to reach the service when matching on the URI. The default value is StrongWildcard, which ignores the hostname in the match.

listenBacklog

A positive integer that specifies the maximum number of channels waiting to be accepted on the listener. Connections in excess of this limit are queued until space below the limit becomes available. The connectionTimeout attribute limits the time a client will wait to be connected before throwing a connection exception. The default is 10.

maxBufferPoolSize

An integer that specifies the maximum buffer pool size for this binding. The default is 512 * 1024 bytes. 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.

maxBufferSize

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. This value cannot be less than maxReceivedMessageSize attribute. The default is 65536. For more information, see MaxBufferSize.

maxConnections

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.

The default is 10.

maxReceivedMessageSize

A positive integer that specifies the maximum message size, in bytes, including headers, that can be received on a channel configured with this binding.. 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. The default is 65536.

name

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.

openTimeout

A TimeSpan value that specifies the interval of time provided for an open operation to complete. This value should be greater than or equal to Zero. The default is 00:01:00.

portSharingEnabled

A Boolean value that specifies whether TCP port sharing is enabled for this connection. If this is false, each binding uses its own exclusive port. This setting is relevant only to services, because clients are not affected.

receiveTimeout

A TimeSpan value that specifies the interval of time provided for a receive operation to complete. This value should be greater than or equal to Zero. The default is 00:10:00.

sendTimeout

A TimeSpan value that specifies the interval of time provided for a send operation to complete. This value should be greater than or equal to Zero. The default is 00:01:00.

transactionFlow

A Boolean value that specifies whether the binding supports flowing WS-Transactions. The default is false.

transactionProtocol

Specifies the transaction protocol to be used with this binding. Valid values are

  • OleTransactions

  • WSAtomicTransactionOctober2004

The default is OleTransactions. This attribute is of type TransactionProtocol.

transferMode

A TransferMode value that specifies whether messages are buffered or streamed or a request or response.

Child Elements

Element Description

<security> of <netTcpBinding>

Defines the security settings for the binding. This element is of type NetTcpSecurityElement.

<readerQuotas>

Defines the constraints on the complexity of SOAP messages that can be processed by endpoints configured with this binding. This element is of type XmlDictionaryReaderQuotasElement.

reliableSession

Specifies if reliable sessions are established between channel endpoints.

Parent Elements


Element Description

<bindings>

This element holds a collection of standard and custom bindings. Each entry is identified by its name. Services use bindings by linking them using the name.

Example

The binding is specified in the configuration files for the client and service. The binding type is specified in the binding attribute of the <endpoint> element. If you want to configure the netTcpBinding binding and change some of its settings, it is necessary to define a binding configuration. The endpoint must reference the binding configuration by name with a bindingConfiguration attribute. In the following example, the binding configuration is named Binding1 and is defined as shown.

<services>
  <service name="Microsoft.ServiceModel.Samples.CalculatorService"
           behaviorConfiguration="CalculatorServiceBehavior">
    ...
    <endpoint address=""
              binding="netTcpBinding"
              bindingConfiguration="Binding1" 
              contract="Microsoft.ServiceModel.Samples.ICalculator" />
    ...
  </service>
</services>

<bindings>
  <netTcpBinding>
    <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" 
             listenBacklog="10"
             maxBufferPoolSize="524288" 
             maxBufferSize="65536" 
             maxConnections="10"
             maxReceivedMessageSize="65536">
      <readerQuotas maxDepth="32" 
                    maxStringContentLength="8192" 
                    maxArrayLength="16384"
                    maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
      <reliableSession ordered="true" 
                       inactivityTimeout="00:10:00"
                       enabled="false" />
      <security mode="Transport">
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>

See Also

Reference

NetTcpBinding

Footer image

Send comments about this topic to Microsoft.
© Microsoft Corporation. All rights reserved.