tags:

views:

36

answers:

2

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.

A: 

There is no connection pooling. If you want to reuse security context you have to use same WCF client proxy. So instead of closing proxy after each call, keep the proxy opened and reuse it for several calls. This has another disadvantages because you have to deal with network errors and timeouts which can occur between subsequent calls.

Ladislav Mrnka
That's what I suspected. Thanks.
Oliver Weichhold
This is not entirely true. As for the security context, yes. But e.g. creating and destroying a proxy does not physically establish a new HTTP connection everytime. That would exhaust your ephemeral ports like crazy.
Alex
But my answer targets connection with security context. In such scenarions caching proxy with security context can have better performance then authentication each call. HTTP persistant connection remains open for another proxy (or until it timeouts - 100s) even if you use the context.
Ladislav Mrnka
+1  A: 

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!!

David Hoerster
What the article doesn't say: a proxy times out depending on your binding! For a WSHttpBinding the default timeout is 10mins.
Alex
Don't forget to set estabilishSecurityContext=false and negotiateServiceCredential=false on your wsHttpBinding.
Ladislav Mrnka