我们已经将我们的服务行为设置为 [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 &ConcurrencyMod
发布评论