成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

關(guān)于WCF緩存機(jī)制介紹

開(kāi)發(fā) 后端
這里就WCF緩存做出了詳細(xì)的案例分析,實(shí)現(xiàn)BehaviorExtensionElement,IEndpointBehavior將剛剛建立的行為加入Client行為集合,文章有詳細(xì)的代碼。

緩存是很占內(nèi)存的,緩存也有它的好處,這里就WCF緩存機(jī)制分析一個(gè)案例,希望大家可以從中得到收獲。首先我們看看MSDN中對(duì)WCF的Session的說(shuō)明:它們由調(diào)用應(yīng)用程序顯式啟動(dòng)和終止。會(huì)話期間傳遞的消息按照接收消息的順序進(jìn)行處理。會(huì)話將一組消息相互關(guān)聯(lián),從而形成對(duì)話。該關(guān)聯(lián)的含義是抽象的。

#T#例如,一個(gè)基于會(huì)話的通道可能會(huì)根據(jù)共享網(wǎng)絡(luò)連接來(lái)關(guān)聯(lián)消息,而另一個(gè)基于會(huì)話的通道可能會(huì)根據(jù)消息正文中的共享標(biāo)記來(lái)關(guān)聯(lián)消息。可以從會(huì)話派生的功能取決于關(guān)聯(lián)的性質(zhì)。不存在與 WCF 會(huì)話相關(guān)聯(lián)的常規(guī)數(shù)據(jù)存儲(chǔ)區(qū)。***一句告訴我們,WCF中的Session是無(wú)法像Web應(yīng)用一樣存儲(chǔ)附加信息的。經(jīng)過(guò)研究,我們可以通過(guò)擴(kuò)展MessageHeader實(shí)現(xiàn)一個(gè)附加的數(shù)據(jù)存儲(chǔ)區(qū)在Client端每次請(qǐng)求Service時(shí)發(fā)送到Server端。具體實(shí)現(xiàn)如下(以前述需求為例)。

這是一個(gè)單件類(lèi),Client正常登陸得到Server端回傳的UserIdentity實(shí)例后可以通過(guò)如下代碼將其存入WCF緩存:

  1. UserPermissionInfo.GetInstance().SetUserIdentity(ServerReturnedUserIdentity); 

其中ServerReturnedUserIdentity就是Server產(chǎn)生并回傳的UserIdentity下面我們擴(kuò)展MessageHeader將我們自己定義的UserIdentity加入進(jìn)去,WCF緩存代碼如下:

  1. usingSystem;  
  2. usingSystem.Collections.Generic;  
  3. usingSystem.Text;  
  4. usingSystem.ServiceModel;  
  5. usingSystem.ServiceProcess;  
  6. usingSystem.ServiceModel.Dispatcher;  
  7. usingSystem.ServiceModel.Description;  
  8. usingSystem.ServiceModel.Channels;  
  9. usingSystem.ServiceModel.Configuration;  
  10. namespaceBNCommon.ClientHelper  
  11. {  
  12. publicclassBNClientMessageInspector:IClientMessageInspector  
  13. {  
  14. IClientMessageInspector成員#regionIClientMessageInspector成員  
  15. publicvoidAfterReceiveReply(refMessagereply,objectcorrelationState)  
  16. {  
  17. }  
  18. publicobjectBeforeSendRequest(refMessagerequest,IClientChannelchannel)  
  19. {  
  20. MessageHeaderMessageHeadermh=MessageHeader.CreateHeader("UserIdentity","UINS",BNIIClientLayerPlus.UserPermissionInfo.GetInstance()._UserIdentity);  
  21. request.Headers.Add(mh);  
  22. returnnull;  
  23. }  
  24. #endregion  
  25. }  


這個(gè)類(lèi)實(shí)現(xiàn)了IClientMessageInspector接口,實(shí)現(xiàn)該接口可以在Client每次向Server請(qǐng)求前及請(qǐng)求返回后控制Client的行為對(duì)發(fā)送和接收的數(shù)據(jù)進(jìn)行處理。現(xiàn)在我們需要實(shí)現(xiàn)BehaviorExtensionElement,IEndpointBehavior將剛剛建立的行為加入Client行為集合,代碼如下:

  1. usingSystem;  
  2. usingSystem.Collections.Generic;  
  3. usingSystem.Text;  
  4. usingSystem.ServiceModel;  
  5. usingSystem.ServiceProcess;  
  6. usingSystem.ServiceModel.Dispatcher;  
  7. usingSystem.ServiceModel.Description;  
  8. usingSystem.ServiceModel.Channels;  
  9. usingSystem.ServiceModel.Configuration;  
  10. namespaceBNCommon.ClientHelper  
  11. {  
  12. publicclassBNClientEndpointBehavior:BehaviorExtensionElement,IEndpointBehavior  
  13. {  
  14. IEndpointBehavior成員#regionIEndpointBehavior成員  
  15. publicvoidAddBindingParameters(ServiceEndpointendpoint,BindingParameterCollectionbindingParameters)  
  16. {}  
  17. publicvoidApplyClientBehavior(ServiceEndpointendpoint,ClientRuntimeclientRuntime)  
  18. {  
  19. clientRuntime.MessageInspectors.Add(newBNClientMessageInspector());  
  20. }  
  21. publicvoidApplyDispatchBehavior(ServiceEndpointendpoint,EndpointDispatcherendpointDispatcher)  
  22. {  
  23. }  
  24. publicvoidValidate(ServiceEndpointendpoint)  
  25. {  
  26. return;  
  27. }  
  28. #endregion  
  29. publicoverrideTypeBehaviorType  
  30. {  
  31. get...{returntypeof(BNClientEndpointBehavior);}  
  32. }  
  33. protectedoverrideobjectCreateBehavior()  
  34. {  
  35. returnnewBNClientEndpointBehavior();  
  36. }  
  37. }  


 

責(zé)任編輯:田樹(shù) 來(lái)源: 博客
相關(guān)推薦

2009-12-07 18:33:31

WCF Service

2009-11-09 13:47:22

WCF Stream操

2016-03-09 09:54:47

Python開(kāi)發(fā)緩存機(jī)制

2010-02-26 13:34:50

WCF編碼機(jī)制

2010-03-01 17:57:11

WCF緩存機(jī)制

2009-11-09 14:15:17

WCF集合類(lèi)型

2009-06-12 14:28:14

WCF傳輸安全

2009-11-09 13:04:53

WCF事物處理

2009-11-09 16:44:18

WCF Service

2009-11-06 11:07:52

WCF事務(wù)屬性

2009-11-05 11:31:00

WCF綁定

2009-11-09 17:30:20

WCF元數(shù)據(jù)

2010-02-24 15:28:59

WCF ABC

2009-12-07 09:23:05

2009-12-22 17:30:47

WCF Address

2009-12-22 15:14:33

WCF調(diào)用

2009-12-22 15:02:40

WCF限流

2009-12-04 17:35:51

WCF 服務(wù)

2010-02-22 14:18:34

WCF服務(wù)驗(yàn)證

2010-02-23 09:51:32

WCF MTOM
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 国产一二区免费视频 | 天堂一区二区三区 | 免费黄色成人 | 欧美一级欧美一级在线播放 | 先锋资源吧 | 超碰av免费 | 夏同学福利网 | 在线视频亚洲 | 自拍偷拍精品 | 一级片免费视频 | 欧美电影免费观看 | 成人在线播放 | 成人精品久久日伦片大全免费 | 男女网站免费观看 | 国产一区二区三区四区五区加勒比 | 国产欧美在线一区二区 | 日韩91 | 精品一区二区三区在线观看国产 | 日韩在线不卡 | 成人免费看片 | 91精品国产一区二区三区 | 无码日韩精品一区二区免费 | 91视频一区 | 欧美日本一区 | 91中文在线观看 | 久久一级 | 国产精品免费在线 | 亚洲欧美日韩国产综合 | 综合一区二区三区 | 欧美成人一区二免费视频软件 | 国产精品高清在线 | 少妇性l交大片免费一 | 在线观看精品视频网站 | 国产精品欧美一区二区三区 | 91在线免费视频 | 在线日韩精品视频 | 日韩综合在线 | 久久男人| www.国产精 | 日韩欧美亚洲 | 奇米av |