zoukankan      html  css  js  c++  java
  • WCF 中状态的保存

    WCF 状态的保存分为两步:
          (1) 使用SessionMode 来使Session有效化
                

                [ServiceContract(SessionMode=SessionMode.Required)]
                public interface ICalculator
                {
                        [OperationContract(IsOneWay=true)]
                        void Adds(double x);

                        [OperationContract]
                        double GetResult();
                }

          (2)ServiceBehavior 里面利用参数InstanceContextMode设定到底使用哪一种Session方式
                

                [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
                public class CalculatorService:ICalculator
              {
                  private double _result;

                  public double Result
                  {
                      get { return _result; }
                      set { _result = value; }
                  }

                  public void Adds(double x)
                  {
                      Console.WriteLine("The Add Method is invoked and The current SessionID is {0} ",OperationContext.Current.SessionId);
                      this._result += x;
                  }

                  public double GetResult()
                  {
                      Console.WriteLine("The GetResult Method is invoked and The current SessionID is {0} ", OperationContext.Current.SessionId);
                      return this._result;
                  }

                  public CalculatorService()
                  {
                      Console.WriteLine("CalculatorService object has been Created ");
                  }


                  ~CalculatorService()
                  {
                      Console.WriteLine("CalculatorService object has been destoried ");
                  }

              }


    SessionMode 有三种值:
    (1)Allowed 默认选值,允许但不强制使用Session
    (2)Required 强制使用Session
    (3)NotAllowed 不允许使用Session 

    InstanceContextMode 有三种值:
    (1) Percall 为user的每一次调用生成一个SessionID
          生命周期:调用开始 ---->调用结束,这种情况和不使用Session是一样的
    (2) PerSession 为每个用户生成一个SessionID
          生命周期:客户端代理生成--->客户端代理关闭   和最原先的Session是一样的
    (3) Seigle 生成唯一的SessionID,所有的用户共享 从host创建---->host 关闭,和Application 一样

  • 相关阅读:
    jQuery 间歇式无缝滚动特效分享(三张图片平行滚动)
    百度网页分享js代码
    如何在linux中搭建JEECMS系统
    Python菜鸟之路:Python基础-类(2)——成员、成员修饰符、异常及其他
    Python菜鸟之路:Python基础-类(1)——概念
    Python菜鸟之路:Python基础-生成器和迭代器、递归
    Python菜鸟之路:Python基础-逼格提升利器:装饰器Decorator
    Python菜鸟之路:Python基础-内置函数补充
    Python菜鸟之路:Python基础——函数
    Python菜鸟之路:Python基础(三)
  • 原文地址:https://www.cnblogs.com/qingyuan/p/1513377.html
Copyright © 2011-2022 走看看