日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

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

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

在客戶端代理觸發(fā)終止操作前,WCF 為每個(gè)客戶端維持同一個(gè)服務(wù)對(duì)象,因此 PreSession 模式可用來(lái)保持調(diào)用狀態(tài)。也正因?yàn)槿绱?,PreSession 在大并發(fā)服務(wù)上使用時(shí)要非常小心,避免造成服務(wù)器過(guò)度負(fù)擔(dān)。雖然支持 Session 的 Binding 對(duì)象缺省就會(huì)啟用 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

網(wǎng)站題目:WCF服務(wù)實(shí)例管理模式之PreSession應(yīng)用
分享路徑:http://m.5511xx.com/article/coocgph.html