新聞中心
WCF已經推出就深受廣大開發(fā)人員的喜愛。它的強大的功能可以幫助我們輕松的打造一個跨平臺的安全性高的解決方案。在這里我們可以先從WCF狀態(tài)保存的方法來對此進行一個分析,加深其的印象。

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供寧江網站建設、寧江做網站、寧江網站設計、寧江網站制作等企業(yè)網站建設、網頁設計與制作、寧江企業(yè)網站模板建站服務,十多年寧江做網站經驗,不只是建網站,更提供有價值的思路和整體網絡服務。
WCF狀態(tài)保存分為兩步:
(1) 使用SessionMode 來使Session有效化
- [ServiceContract(SessionModeSessionMode=SessionMode.Required)]
- public interface ICalculator
- {
- [OperationContract(IsOneWay=true)]
- void Adds(double x);
- [OperationContract]
- double GetResult();
- }
(2)ServiceBehavior 里面利用參數InstanceContextMode設定到底使用哪一種Session方式
- [ServiceBehavior(InstanceContextModeInstanceContextMode=
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 有三種值:#t#
(1)Allowed 默認選值,允許但不強制使用Session
(2)Required 強制使用Session
(3)NotAllowed 不允許使用Session
InstanceContextMode 有三種值:
(1) Percall 為user的每一次調用生成一個SessionID
WCF狀態(tài)保存生命周期:調用開始 ---->調用結束,這種情況和不使用Session是一樣的
(2) PerSession 為每個用戶生成一個SessionID
生命周期:客戶端代理生成--->客戶端代理關閉 和最原先的Session是一樣的
(3) Seigle 生成***的SessionID,所有的用戶共享 從host創(chuàng)建---->host 關閉,和Application 一樣
WCF狀態(tài)保存的相關內容就為大家介紹到這里。
分享文章:WCF狀態(tài)保存不同方法介紹
文章URL:http://m.5511xx.com/article/djcisji.html


咨詢
建站咨詢
