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

深入探討WCF緩存機制基本概念

開發 開發工具
我們今天將會在這篇文章中,通過一個簡單的示例來為大家詳細解讀一下WCF緩存機制的基本概念,希望可以給大家帶來一些幫助。

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

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

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

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

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

其中ServerReturnedUserIdentity就是Server產生并回傳的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 } }  

這個類實現了IClientMessageInspector接口,實現該接口可以在Client每次向Server請求前及請求返回后控制Client的行為對發送和接收的數據進行處理。現在我們需要實現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緩存機制的基本介紹。

責任編輯:曹凱 來源: IT專家網
相關推薦

2010-11-22 14:18:32

MySQL鎖機制

2010-07-21 09:38:15

PHP緩存技術

2009-12-21 10:27:52

WCF基本概念

2010-02-23 16:32:29

WCF服務

2009-12-16 16:44:31

Ruby on Rai

2009-12-10 15:02:07

OSPF動態路由協議

2009-12-21 15:33:07

WCF集合元素

2010-03-01 14:50:30

WCF行為類型

2010-03-01 18:04:35

WCF配置綁定

2010-02-24 17:17:04

WCF宿主環境

2010-03-02 13:14:38

WCF MSMQ隊列

2010-03-01 16:25:07

WCF體系架構

2009-12-21 14:37:14

2010-03-01 16:41:04

WCF數據表

2010-03-02 16:22:31

WCF狀態應用

2009-12-21 16:52:02

WCF序列化

2009-12-22 10:16:54

WCF服務狀態

2010-03-02 11:10:43

WCF標準終結點

2010-02-25 14:46:31

2009-12-23 16:13:00

WPF Attache
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产日韩视频在线 | 国产一区www| 日韩精品一区中文字幕 | 国产激情免费视频 | 蜜桃av鲁一鲁一鲁一鲁 | 久久久久久久久久爱 | 国产清纯白嫩初高生在线播放视频 | 久久成人精品一区二区三区 | 国产精品久久久久久久久污网站 | 国产乱码精品一区二区三区中文 | 国产视频福利 | 亚洲精品欧美一区二区三区 | 久久久久久久91 | 午夜爱爱毛片xxxx视频免费看 | 一级毛片视频 | 一二区成人影院电影网 | 久久午夜精品福利一区二区 | 国产视频福利一区 | 国产99久久精品一区二区永久免费 | 国产一区免费 | 欧美二区在线 | 射久久| 日韩一区二区精品 | 精品中文在线 | 日本一区二区视频 | 欧美成人精品一区二区三区 | 91成人在线 | 久久久久中文字幕 | 国产成人精品一区二区 | 亚洲精品久久久久久久久久久久久 | 中文在线一区二区 | 97精品超碰一区二区三区 | 日韩视频一区二区 | a级网站 | 欧美一区二区视频 | 九九热在线精品视频 | 精品国产伦一区二区三区观看方式 | 国产在线视频一区二区 | 国产精品一区二区三区免费观看 | 免费一区二区三区在线视频 | 日韩精品一区二区三区久久 |