开发者

WCF ConcurrencyMode.Multiple Connection best practices and Caching

开发者 https://www.devze.com 2022-12-09 09:31 出处:网络
I\'ve got a WCF service with the following settings: NetNamedPipeBinding ConcurrencyMode.Multiple InstanceContextMode.Single

I've got a WCF service with the following settings:

  • NetNamedPipeBinding
  • ConcurrencyMode.Multiple
  • InstanceContextMode.Single

Now I've got a client that accesses to this WCF service in a multi-threaded fashion.

As far as I understand I have to open a new connection to the service for each thread to avoid threads to block each others.

  • In this case how expensive is the Open() call (service is in the same computer)?
  • Shall I cache/pool the my client class? (derived from ClientBase) or 开发者_Python百科does WCF provides a transparent pool for connections similar to SQLConnection Pooling?


WCF unfortunately does not pool client connections. I've found that Open() is relatively slow and have built my own pooling mechanisms keeping a handful of persistent connections open between the client and server.

One common gotcha though regarding this is that if even something as simple as a time-out occurs between the client and server (or any sort of CommunicationException is thrown), the client instance enters a Faulted state and becomes unusuable. At which time you must destroy and replace it w/ a new instance.


James Alexander's answer is spot on (you have to pool connections yourself), but I figured I'd post a link to a blog entry that discusses an implementation that adds connection pooling on top of ClientBase. Here's the follow up post where he goes into details and provides a link to download the code.

0

精彩评论

暂无评论...
验证码 换一张
取 消