日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
WCF服務(wù)實例管理模式之PreSession應(yīng)用

在WCF服務(wù)實例管理模式中,總共有三種應(yīng)用模式可以供開發(fā)人員選擇應(yīng)用。今天主要就是針對其中一個比較常用的PreSession模式進(jìn)行一些相關(guān)介紹。PreSession 模式需要綁定到支持 Session 的 Binding 對象。

在客戶端代理觸發(fā)終止操作前,WCF 為每個客戶端維持同一個服務(wù)對象,因此 PreSession 模式可用來保持調(diào)用狀態(tài)。也正因為如此,PreSession 在大并發(fā)服務(wù)上使用時要非常小心,避免造成服務(wù)器過度負(fù)擔(dān)。雖然支持 Session 的 Binding 對象缺省就會啟用 PreSession 模式,但依然建議你強(qiáng)制指定 SessionMode.Required 和 InstanceContextMode.PerSession。

 
 
 
  1. [ServiceContract(SessionMode = SessionMode.Required)]
  2. public interface IMyService
  3. {
  4. [OperationContract]
  5. void Test();
  6. }
  7. [ServiceBehavior(InstanceContextMode = 
    InstanceContextMode.PerSession)]
  8. public class MyServie : IMyService, IDisposable
  9. {
  10. public MyServie()
  11. {
  12. Console.WriteLine("Constructor:{0}", this.GetHashCode());
  13. }
  14. [OperationBehavior]
  15. public void Test()
  16. {
  17. Console.WriteLine("Test:{0}", OperationContext.Current.SessionId);
  18. }
  19. public void Dispose()
  20. {
  21. Console.WriteLine("Dispose");
  22. }
  23. }
  24. public class WcfTest
  25. {
  26. public static void Test()
  27. {
  28. AppDomain.CreateDomain("Server").DoCallBack(delegate
  29. {
  30. ServiceHost host = new ServiceHost(typeof(MyServie), 
    new Uri("http://localhost:8080/MyService"));
  31. host.AddServiceEndpoint(typeof(IMyService), 
    new WSHttpBinding(), "");
  32. host.Open();
  33. });
  34. //-----------------------
  35. IMyService channel = ChannelFactory.
    CreateChannel(new WSHttpBinding(), 
  36. new EndpointAddress("http://localhost:8080/MyService"));
  37. using (channel as IDisposable)
  38. {
  39. channel.Test();
  40. channel.Test();
  41. }
  42. }
  43. }

輸出:

 
 
 
  1. Constructor:30136159
  2. Test:urn:uuid:2f01b61d-40c6-4f1b-a4d6-4f4bc3e8847a
  3. Test:urn:uuid:2f01b61d-40c6-4f1b-a4d6-4f4bc3e8847a
  4. Dispose

當(dāng)前標(biāo)題:WCF服務(wù)實例管理模式之PreSession應(yīng)用
網(wǎng)頁鏈接:http://www.dlmjj.cn/article/coocgph.html