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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
關(guān)于WCF緩存機(jī)制介紹

緩存是很占內(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)的含義是抽象的。

在通江等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專(zhuān)注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計(jì),全網(wǎng)營(yíng)銷(xiāo)推廣,成都外貿(mào)網(wǎng)站制作,通江網(wǎng)站建設(shè)費(fèi)用合理。

#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. }  

網(wǎng)站欄目:關(guān)于WCF緩存機(jī)制介紹
當(dāng)前路徑:http://www.dlmjj.cn/article/dhdhcjg.html