Sessions, Instancing and Concurrency in WCF

Posted By : Bipul Kumar Tiwari,

WCF session:


WCF session means to combine several message together into a single conversation. WCF session are set by “SessionMode” Attributes.

Configure Sessions in WCF:


To configure sessions in WCF, We should know the following three elements. Binding, SessionMode and InstanceContextMode

  1. Binding:


  2. SessionMode :


  3. Ex. [ServiceContract(SessionMode=SessionMode.Required)]
    public interface IContractorService

    WCF session is somewhat different than ASP.NET sessions in the following ways as in WCF:


    Note: all bindings do not support sessions. Only WSHttpBinding, WSDualHttpBinding, WSFederationHttpBinding , NetTcpBinding and NetNamedPipeBinding have session support

  4. InstanceContextMode :


  5. For more detial for Instance Management: Instance management in WCF

Managing Concurrency:


Concurrency refers to the number of threads executing at the same time in a service instance. You can control concurrency by setting the ConcurrencyMode property of the ServiceBehavior attribute. There are three possible values for this property:


By default, only one thread at a time can access the service object. The first call to the service locks the service object. The service object queues additional calls in the order it receives them. When the first call finishes, the next call in the queue locks the service. The benefit to this approach is that there is no risk of two calls reading the same memory and changing the same data.


If the service makes callbacks to the client, you can set the ConcurrencyMode property to Reentrant. When the client calls the service, it locks the service object. The service object releases the lock when the call finishes. When the service calls back to the client, it locks the service object and uses the same thread. The upcoming Messaging Patterns tutorial in this series covers callbacks.


If you set the ConcurrencyMode property to Multiple, more than one thread at a time can access the service object. The WCF runtime assigns a thread to each client call and they execute simultaneously. The benefit to this approach is increased throughput, particularly in situations where methods take an appreciable amount of time to run.


Related Articles

 

About the Author

author
Its me BIPUL who is logically minded creative at heart , a good communicator , a self taught full stack developer. I constantly focuses on my thinking , reading , collecting and creating my work in a order to enhance my skills.

I discover new dimensions for growing bussiness with a proven record in creating database and programming. I have a strong technical skills as well as strong interpersonal skills. Read more...
 

Browse By Category

Popular Articles