WCF - 处理来自多个客户端的请求
我的 WCF 服务库作为 Windows 服务托管,应该处理来自多个客户端的请求。 客户经常提出的一项请求是相当资源密集型的。
我对上述场景有两个疑问:
- WCF服务如何处理多个客户端的请求?
- 是否有任何 WCF 配置可以提高该过程的效率?
谢谢你!
My WCF service library is hosted as a Windows Service and is supposed to handle requests from multiple clients.
One request that clients are going to make frequently is pretty resource intensive.
I have two doubts pertaining to above scenerio:
- How a WCF service handles multiple client's request?
- Is there any WCF configuration to make the process efficient?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在默认情况下,WCF 服务主机(托管服务类的事物)将为每个传入的请求创建服务类的新实例,并让其处理该请求(“每次调用”激活)。
您可以使用服务器上的
serviceThrotdling
行为来调整并发活动服务类实例的最大数量。Kenny Wolf 的博客文章在这里。
此外,服务类(实现服务协定)上的
InstanceContextMode
和ConcurrencyMode
设置对您的服务处理并发和多个请求的方式有很大影响。InstanceContextMode
应为PerCall
(每个调用请求都会获得一个新的单独实例),然后ConcurrencyMode
可以为Single
(这是最容易开发的)。如果您需要基于会话的方法(不是很常见),
InstanceContextMode
也可以是PerSession
,或者Single
(您的服务类将是单例 -强烈建议不要使用此功能,除非您绝对必须、必须了解它的所有怪癖和问题!)。ConcurrencyMode
也可以是Reentrant
(仅与双工合约和绑定相关)或Multiple
(多线程单例服务类 - 高风险且难以开发! )。马克
In your default scenario, the WCF service host (the thing hosting your service class) will create a new instance of your service class for each request that comes in, and lets that handle the request ("per-call" activation).
You can tweak the maximum number of those concurrently active service class instances using the
serviceThrottling
behavior on your server.There's a really good explanation of the options of the service throttling behavior and its default values in Kenny Wolf's blog post here.
Also, setting of the
InstanceContextMode
andConcurrencyMode
on your service class (that implements the service contract) have a strong influence on how your service will handle concurrency and multiple requests.InstanceContextMode
should bePerCall
(each calling request gets a new, separate instance) and thenConcurrencyMode
can beSingle
(which is the easiest to develop).InstanceContextMode
could also bePerSession
if you need a session-based approach (not very common), orSingle
(your service class would a singleton - highly discouraged to use this, unless you absolutely, positively have to and know about all the quirks and problems with it!).ConcurrencyMode
could also beReentrant
(only relevant for duplex contracts and bindings) orMultiple
(multithreaded singleton service class - highly risky and difficult to develop!).Marc