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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
深入探討WCF緩存機制基本概念

WCF開發(fā)工具是一個由微軟公司開發(fā)的功能強大的開發(fā)插件。它的應用可以幫助我們實現(xiàn)包括在通信方面的各種功能需求。那么接下來,我們將會為大家分析一下其中一個比較基礎的內(nèi)容,WCF緩存機制的相關概念。#t#

公司主營業(yè)務:做網(wǎng)站、網(wǎng)站制作、移動網(wǎng)站開發(fā)等業(yè)務。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)推出來賓免費做網(wǎng)站回饋大家。

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

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

這是一個單件類,Client正常登陸得到Server端回傳的UserIdentity實例后可以通過如下代碼將其存入WCF緩存機制:

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

其中ServerReturnedUserIdentity就是Server產(chǎn)生并回傳的UserIdentity下面我們擴展MessageHeader將我們自己定義的UserIdentity加入進去,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. publicclassBNClientMessageInspector:IClientMessageInspector 
    { IClientMessageInspector成員  
  12. #regionIClientMessageInspector成員   
  13. publicvoidAfterReceiveReply(refMessagereply,objectcorrelationState) { }   
  14. publicobjectBeforeSendRequest(refMessagerequest,IClientChannelchannel) {   
  15. MessageHeaderMessageHeaderMessageHeadermh=MessageHeader.CreateHeader
    ("UserIdentity","UINS",BNIIClientLayerPlus.UserPermissionInfo
    .GetInstance()._UserIdentity);   
  16. request.Headers.Add(mh);   
  17. returnnull; }   
  18. #endregion } }  

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

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

以上就是對WCF緩存機制的基本介紹。


名稱欄目:深入探討WCF緩存機制基本概念
本文來源:http://www.dlmjj.cn/article/dpghhcg.html