Sunday 15 September 2013

performance - WCF ChannelFactory and Channel caching in ASP.NET client application -


I am creating a series of WCF services that are being used by more than one app because of the WCF I'm trying to define a general library to access services.

To know that different users must use a different channel for each service request, I am thinking of the channel per-request cache ( HttpContext.Current.Items ) And ChannelFactory are used to create per channel ( HttpApplication.Items ) channel because I can create more than one channel from the same ChannelFactor .

However, in relation to closing channel fighter and channel, I have a question about this cache mechanism

  1. Can I use the channel at the end of the request After shutdown, or to close it, to fix it (?) When the reference to that request dies?
  2. What about ChannelFount? Since each channel is connected to the channelfactor, which is made, is it safe to maintain the same channelphiniter during the application process (App Doxane)?

To manage this I am using:

  Public class ServiceFactory {Private Stable Dictionary & lt; String, Object & gt; List unfolded channels [get {if (null == HttpContext.Current.Items [HttpContext.Current.Session.sidid + "_ListOfOpenedChannels"]) {HttpContext.Current.Items [HttpContext.Current.Session.SessionID + "_ListOfOpenedChannels"] = New Dictionary & Lieutenant; String, Object & gt; (); } Return (dictionary & lt; string, object & gt;) HttpContext.Current.Items [HttpContext.Current.Session.SessionID + "_ListOfOpenedChannels"]; } Set {HttpContext.Current.Items [HttpContext.Current.Session.SessionID + "_ListOfOpenedChannels"] = Value; }} Public Static T CreateServiceChannel & lt; T & gt; () {String key = typeof (T) .name; If (ListOfOpenedChannels.ContainsKey (key)) {Return (t) listoffocked channel [key]; } And {ChannelFlate & lt; T & gt; ChannelF = new channel factory & lt; T & gt; ("IUsuarioService"); T channel = channelF.CreateChannel (); ListoffApplied Channel Add (key, channel); Return channel; }}}  

Thanks!

Ideally close the channel as soon as you are done with it back into the channel pool So that it can be used by another worker thread.

Yes, the channel factory (expensive bit) can live in the lifetime of the application.


Update

.Net 4.5 is one of the caching options for factories as


No comments:

Post a Comment