首页 > 其他 > 详细

WCF实例上下文与并发

时间:2015-04-05 13:21:51      阅读:245      评论:0      收藏:0      [点我收藏+]

一、实例上下文模式(InstanceContextMode)可以简单地理解为服务端的服务实例与客户端的服务代理之间的关联方式。WCF具有单调(Per-Call)、会话(Per-Session)、和单例(Single)


单调(Per-Call)

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class TestService : ITest


会话(Per-Session)

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    public class TestService : ITest



单例(Single)

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class TestService : ITest


二、并发

通过ServiceBehaviorAttribute特性定义并发模式

WCF为三种典型的并发处理策略定义了Single、Reentrant和Multiple三种典型的并发模式。

Single:一个实例上下文在某个时刻只能用于对单一请求的处理,或者说只针对某个实例上下文的多个并发的请求会以一种串行的方式进行处理。

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, 
    ConcurrencyMode = ConcurrencyMode.Single)]
    public class TestService : ITest



Reentrant:一个实例上下文对象在某个时刻只能用于对单一请求的处理。如果服务操作在执行过程中涉及对客户端的回调(Callback),在 回调过程中该实例上下文可以用于其他服务调用请求的处理。如果回调操作执行后服务实例上下文没有用于其他请求的处理,回调后的操作能够得到处理。

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, 
    ConcurrencyMode = ConcurrencyMode.Reentrant)]
    public class TestService : ITest



Multiple:一个实例上下文可以同时用于处理多个服务请求。

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, 
    ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class TestService : ITest



WCF实例上下文与并发

原文:http://blog.csdn.net/zhang116868/article/details/44886971

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!