NetTcpBinding in WCF

The NetTcpBinding provides a secure and reliable binding environment for .NET-to-.NET cross-machine communication. It uses the TCP protocol and provides full support for SOAP security, transactions, and reliability.
At runtime the NetTcpBinding creates a communication stack using the WS-ReliableMessaging protocol for reliability, Windows Security for message security and authentication, and TCP for message delivery.
The WS-ReliableMessaging protocol is an interoperable protocol used by both sender and receiver to ensure safe and reliable delivery of messages between the sender and receiver. The guaranteed delivery is specified as a delivery assurance, and it is the responsibility of the sender and receiver to fulfill the delivery assurance, or generate an error.

NetTcpBinding Properties

The following table is a list of attributes, and their descriptions, that are available to be used with the NetTcpBinding.

Attribute Description
closeTimeout A time interval value, which must be greater than zero, that specifies the amount of time for a close operation to complete. The default value is 1 minute (00:01:00).
hostnameComparisonMode Specifies the HTTP hostname comparison node used to parse URIs. Acceptable values are Exact, StrongWildCard, and WeakWildCard. The default value is StrongWildCard.
listenBackLog Specifies the maximum number of channels waiting to be accepted on the listener. This value is a positive integer with a default of 10.
maxBufferPoolSize Specifies the maximum buffer size for a buffer pool, which stores messages processed by the binding. This is an integer value with a default of 512*1024, or 524388.
maxBufferSize Specifies the maximum buffer size for a buffer that stores messages processed by the binding. This is an integer value with a default of 65536.
maxConnections A positive integer that specifies the maximum number of inbound and outbound connections that the service will create/accept. The default value is 10. Connections that exceed the specified value are
queued until a space below the specified value becomes available.
maxReceivedMessageSize Specifies the maximum size of a message, including headers. The number is specified in bytes with a default value of 65536. If a message is larger than the value specified, the sender receives a SOAP fault message and the receiver drops the message and creates an event in the trace log.
Name A unique string value that contains the configuration name of the binding.
openTimeout A time interval value that specifies the amount of time a message has to complete. Value should be greater than zero. Default is 1 minute (00:01:00).
portSharingEnabled A Boolean value with a default of False, applied only to services, which specifies whether TCP port sharing is enabled for a connection. If false, each binding uses its own specific port.
receiveTimeout A time interval value that specifies the amount of time a receive operation has to complete. Value should be greater than zero. Default is 1 minute (00:01:00).
sendTimeout A time interval value that specifies the amount of time a send operation has to complete. Value should be greater than zero. Default is 1 minute (00:01:00).
transactionFlow Boolean value, default of False, which specifies whether the binding supports flowing WS-Transactions.
transactionProtocol Specifies the transaction protocol to be used with this binding. Available values are OleTransaction and WS-AtomicTransaction. The default is OleTransaction.
transferMode A valid TransferMode value that specifies whether messages are buffered or streamed during a response or request.

The following example illustrates some of the properties being configured in a configuration file:

<system.serviceModel>
<bindings>
<netTCPBinding>
<binding name = “nettcpbind” portsharingenabled = “true” listenbacklog = “10” closeTimeout = “00:00:30” transactionflow = “true”>
</binding>
</netTCPBinding>
</bindings>
</system.ServiceModel>

The same can be done through code, as illustrated here:
 

NetTcpBinding nettcp = new NetTcpBinding();
nettcp.PortSharingEnabled = true;
nettcp.ListenBacklog = 10;
nettcp.CloseTimeout = 30000;
nettcp.TransactionFlow = true;

 
Notes
The maxConnections attribute handles both inbound and outbound connections. If the total number of connections, both inbound and outbound, exceeds the number of specified connections, the connection is queued until the number of connections falls below the specified limit.
The transactionProtocol attribute is of the type TransactionProtocol and is used to specify the transaction protocol when flowing transactions.
The transferMode attribute is of the TransferMode enumeration and specifies whether messages are streamed or buffered on a request or response. The TransferMode enumeration is comprised of the following:

  • Buffered signifies that the request and response messages are buffered.
  • Streamed signifies that the request and response messages are streamed.
  • StreamedRequest signifies that the request message is streamed and the response message is buffered.
  • StreamedResponse signifies that the request message is buffered and the response message is streamed.
Tagged . Bookmark the permalink.

Leave a Reply