Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Client Connection Caching/Pooling

Tags:

wcf

Suppose you expose a WCF Service from one project and consume it in another project using 'Add Service Reference' (in this case a Framework 3.5 WPF Application).

Will ClientBase perform any kind of connection pooling of the underlying channel when you re-instantiate a ClientBase derived proxy or will you incur the full overhead of establishing the connection with the service every time? I am especially concerned about this since we are using security mode="Message" with wsHttpBinding.

like image 737
Oliver Weichhold Avatar asked Aug 18 '10 06:08

Oliver Weichhold


1 Answers

Please take a look at this article which describes best practices on how to cache your client proxies. If you're creating your proxy directly (MyProxy p = new MyProxy(...)), then it seems that you really can't cache the underlying ChannelFactory, which is the expensive part. But if you use ChannelFactory to create your proxy, the ChannelFactory is cached by the proxy at the AppDomain level, and it's based on the parameters you pass to the proxy (kind of like connection pooling which is based on the connection string).

The article goes through a number of details on what's going on under the covers, but the main point is that you get a performance bump if you use ChannelFactory to create your proxy instead of instantiating it directly.

Hope this helps!!

like image 175
David Hoerster Avatar answered Oct 04 '22 01:10

David Hoerster