WCF InstanceContextMode = InstanceContextMode.PerSession &ConcurrencyMode = ConcurrencyMode.Single 在 TraceLog 中仍然不同的 ThreadID [英] WCF InstanceContextMode = InstanceContextMode.PerSession & ConcurrencyMode = ConcurrencyMode.Single still Different ThreadID in TraceLog

查看:56
本文介绍了WCF InstanceContextMode = InstanceContextMode.PerSession &ConcurrencyMode = ConcurrencyMode.Single 在 TraceLog 中仍然不同的 ThreadID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经将我们的服务行为设置为 [ServiceBehavior(Namespace = "abc", InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = false)]

We have set our service behaviour to [ServiceBehavior(Namespace = "abc", InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = false)]

如您所见,我们已将并发模式设置为单一,但我们仍然能够在 WCF 跟踪日志中看到多个 ThreadID.

as you can see we have set Concurrency Mode as Single but still we are able to see multiple ThreadID's in WCF Trace Log.

需要帮助让 WCF 调用线程安全,以便按顺序处理每条消息.

Need Help in making WCF calls Thread Safe so that each message is processed in sequenced.

谢谢,斯鲁哈尔

推荐答案

ConcurrencyMode 控制每个 InstanceContext 的线程.由于您使用 InstanceContextMode = InstanceContextMode.PerSession,您仍然允许同时存在多个服务实例,每个会话一个.

ConcurrencyMode controls threading per InstanceContext. Since you use InstanceContextMode = InstanceContextMode.PerSession you still allow to exist several service instances at the same time, one per session.

如果您改为设置 InstanceContextMode = InstanceContextMode.Single,您将创建一个单例服务,即您的服务只有一个实例.结合 ConcurrencyMode = ConcurrencyMode.Single 这将实现所需的行为:

If you instead set InstanceContextMode = InstanceContextMode.Single you create a singleton service, i.e. only one single instance of your service. In combination with ConcurrencyMode = ConcurrencyMode.Single this will achieve the desired behavior:

服务实例是单线程的,不接受可重入调用.如果 InstanceContextMode 属性为 Single,并且在实例为调用提供服务时有其他消息到达,则这些消息必须等到服务可用或消息超时.(MSDN 文档 ConcurrencyMode)

The service instance is single-threaded and does not accept reentrant calls. If the InstanceContextMode property is Single, and additional messages arrive while the instance services a call, these messages must wait until the service is available or until the messages time out. (MSDN documentation ConcurrencyMode)

您可以在 会话、实例化、和 MSDN 上的并发.

这篇关于WCF InstanceContextMode = InstanceContextMode.PerSession &ConcurrencyMode = ConcurrencyMode.Single 在 TraceLog 中仍然不同的 ThreadID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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