Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does WCF NetTcpBinding provide a persistent connection?

Tags:

c#

wcf

Making a client/server style app using WCF, but I can't find any documentation that explains if the NetTcpBinding provides a persistent connection?

I would like my client to connect and remain connected to the server for weeks at a time. (Yes I know I need to handle disconnects etc..)

Does the NetTcpBinding allow for a long connection such as this? If so is there anything I need to specify or is this default behaviour?

like image 947
Kelly Avatar asked Oct 19 '12 20:10

Kelly


1 Answers

As long as you keep the service host and client proxy alive and opened, the underlying connection in WCF should remain opened as well. Even below that, it appears that the binding uses connections from the TCP connection pool, as found on the NetTcpBinding MSDN page:

The NetTcpBinding uses TCP connection pooling based on the service’s host DNS name and the port number the service is listening on.

I'm not an expert on how TCP connection pooling works, you may want to try a sister site such as ServerFault for more details on this.

If you want control over all this, then the only property I can see that can be tweaked for the out-of-the-box NetTcpBinding is MaxConnections. However, if you're really willing to dive deep you can also build your own Custom Binding with a TcpTransportBindingElement, that gives you even more fine-grained control on the TcpConnectionPoolSettings.

In any case, if I were to venture a guess I'd think building the service host and client proxy will take far more time (relatively) than any time spent getting a connection from the pool, so keeping those two opened may be enough for your requirements.

The reason I asked in a comment why you want the connection to remain open is because that can hardly be a requirement in itself. Speed and response times are a real requirement though, so the best advice is probably to make those requirements explicit (quantify / qualify your need for speed) and run some tests to determine what's best/needed for your situation.

like image 139
Jeroen Avatar answered Sep 20 '22 11:09

Jeroen