WCF ConcurrencyMode.Multiple连接的最佳实践和缓存

编程入门 行业动态 更新时间:2024-10-27 04:34:36
本文介绍了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连接的最佳实践和缓存

本文发布于:2023-11-09 03:10:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571233.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   WCF   ConcurrencyMode   Multiple

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!