WCF InstanceContextMode = InstanceContextMode.PerSession &ConcurrencyMode = ConcurrencyMode.

编程入门 行业动态 更新时间:2024-10-26 18:27:24
本文介绍了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 &ConcurrencyMod

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

发布评论

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

>www.elefans.com

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