我有一个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连接的最佳实践和缓存
发布评论