WCF ConcurrencyMode.Multiple连接的最佳实践和缓存 [英] WCF ConcurrencyMode.Multiple Connection best practices and Caching

查看:543
本文介绍了WCF ConcurrencyMode.Multiple连接的最佳实践和缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF服务具有以下设置:

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

  • NetNamedPipeBinding
  • ConcurrencyMode.Multiple
  • InstanceContextMode.Single

现在我已经得到了访问在一个多线程的方式这WCF服务的客户端。

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.

  • 在这种情况下,多贵的是打开()通话(服务在同一台计算机的)?
  • 难道我缓存/池我的客户端类? ( ClientBase派生 的),或者做WCF提供了连接类似的SQLConnection池透明池
  • 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 does WCF provides a transparent pool for connections similar to SQLConnection Pooling?

推荐答案

WCF遗憾的是不集中的客户端连接。我发现,开放式()是比较慢的,并已建成保持了一把永久连接的客户端和服务器之间的公开我自己的池机制。

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.

一个常见的​​问题,虽然这方面是,如果连这样简单的超时发生在客户端和服务器之间(或任何形式的CommunicationException被抛出),客户机实例进入故障状态,并成为unusuable。在这时候,你必须摧毁它取代瓦特/一个新的实例。

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.

这篇关于WCF ConcurrencyMode.Multiple连接的最佳实践和缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆