c# - convert InstanceContextMode.Single to InstanceContextMode.PerCall -


i have wcf service takes 5 min load database. want best performance out of wcf , found article http://theburningmonk.com/2010/05/wcf-improve-performance-with-greater-concurrency/ states better performance using percall. have anywhere between 2000 , 4000 hits per second.

my problem takes long time load data. per article it's saying create wrapper real service using static variable. not sure how looks , have no idea _container is. chance can give me full example of below?

in cases initialization steps lengthy , unavoidable, or class require number of parameters in constructor (for instance, when programmatically host service retrieve ioc container) parameterless constructor can become problem. around this, create wrapper class , expose wrapper service instead hold static instance of underlying service requests passed on to:

[servicebehavior(instancecontextmode = instancecontextmode.percall)] public class myservicewrapper : imyservicewrapper {     // underlying service container     private static imyservice myservice = _container.resolve<imyservice>();   public myservicewrapper() {     // parameterless constructor nothing, easy constructor } public void dosomething() {     myservice.dosomething(); } 

}

// dummy interface ensure wrapper has same methods underlying service // helps avoid confusion public interface imyservicewrapper : imyservice { } 

for sessionful service, persession instance context mode gives benefit of percall instance context mode , @ same time reduces overhead pay concurrency because new instances of class no longer created each request each session instead.

you can remove logic of fetching service object ioc container:

[servicebehavior(instancecontextmode = instancecontextmode.percall)]     public class myservicewrapper : imyservicewrapper     {         // underlying service container         private static imyservice myservice = new myservice();           public myservicewrapper()         {             // parameterless constructor nothing, easy constructor         }         public void dosomething()         {             myservice.dosomething();         }     }      // dummy interface ensure wrapper has same methods underlying service     // helps avoid confusion     public interface imyservicewrapper : imyservice     {     } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -