In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to understand WCF caching mechanism". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand WCF caching mechanism".
Caching takes up a lot of memory, and caching also has its benefits. Here is a case study of WCF caching mechanism. I hope you can get something from it. First, let's take a look at the description of WCF's Session in MSDN: they are explicitly started and terminated by the calling application. Messages delivered during the session are processed in the order in which they are received. A conversation correlates a set of messages to each other to form a dialogue. The meaning of the association is abstract.
For example, one session-based channel might associate a message based on a shared network connection, while another session-based channel might associate a message based on a shared token in the message body. The functionality that can be derived from the session depends on the nature of the association. There is no regular datastore associated with the WCF session. * A sentence tells us that Session in WCF cannot store additional information like Web applications. After research, we can extend MessageHeader to implement an additional data store that is sent to the server every time the client requests Service. The specific implementation is as follows (previously mentioned requirements as an example).
This is a singleton class. After Client logs in to get the UserIdentity instance returned from the server, you can store it in the WCF cache with the following code:
UserPermissionInfo.GetInstance () SetUserIdentity (ServerReturnedUserIdentity)
Where ServerReturnedUserIdentity is the UserIdentity generated and returned by Server. Let's extend MessageHeader to add our own defined UserIdentity. The WCF cache code is as follows:
UsingSystem; usingSystem.Collections.Generic; usingSystem.Text; usingSystem.ServiceModel; usingSystem.ServiceProcess; usingSystem.ServiceModel.Dispatcher; usingSystem.ServiceModel.Description; usingSystem.ServiceModel.Channels; usingSystem.ServiceModel.Configuration; namespaceBNCommon.ClientHelper {publicclassBNClientMessageInspector:IClientMessageInspector {IClientMessageInspector member # regionIClientMessageInspector member publicvoidAfterReceiveReply (refMessagereply,objectcorrelationState) {} publicobjectBeforeSendRequest (refMessagerequest,IClientChannelchannel) {MessageHeaderMessageHeadermh=MessageHeader.CreateHeader ("UserIdentity", "UINS", BNIIClientLayerPlus.UserPermissionInfo.GetInstance (). _ UserIdentity); request.Headers.Add (mh); returnnull } # endregion}}
This class implements the IClientMessageInspector interface, which enables Client to control the behavior of Client before and after each request to Server to process the sent and received data. Now we need to implement BehaviorExtensionElement,IEndpointBehavior to add the newly created behavior to the Client behavior collection, as follows:
UsingSystem; usingSystem.Collections.Generic; usingSystem.Text; usingSystem.ServiceModel; usingSystem.ServiceProcess; usingSystem.ServiceModel.Dispatcher; usingSystem.ServiceModel.Description; usingSystem.ServiceModel.Channels; usingSystem.ServiceModel.Configuration; namespaceBNCommon.ClientHelper {publicclassBNClientEndpointBehavior:BehaviorExtensionElement,IEndpointBehavior {IEndpointBehavior member # regionIEndpointBehavior member publicvoidAddBindingParameters (ServiceEndpointendpoint,BindingParameterCollectionbindingParameters) {} publicvoidApplyClientBehavior (ServiceEndpointendpoint,ClientRuntimeclientRuntime) {clientRuntime.MessageInspectors.Add (newBNClientMessageInspector ());} publicvoidApplyDispatchBehavior (ServiceEndpointendpoint,EndpointDispatcherendpointDispatcher) {} publicvoidValidate (ServiceEndpointendpoint) {return } # endregion publicoverrideTypeBehaviorType {get... {returntypeof (BNClientEndpointBehavior);}} protectedoverrideobjectCreateBehavior () {returnnewBNClientEndpointBehavior ();} Thank you for reading. This is the content of "how to understand the WCF caching mechanism". After the study of this article, I believe you have a deeper understanding of how to understand the WCF caching mechanism, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un