Monday 28 December 2015

What are session modes in WCF? How can you make a service as sessionful?



ServiceContract attribute offers the property SessionMode which is used to specify the session mode. There are three session modes supported by WCF:


  • Session.Allowed(default): Transport sessions are allowed, but not enforced. Service will behave as a per-session service only if the binding used maintains a transport-level session.
  • Session.Required: Mandates the use of a transport-level session, but not necessarily an application-level session.
  • Session.NotAllowed: Disallows the use of a transport-level session, which precludes an application-level session. Regardless of the service configuration, the service will always behave as a per-call service.




[ServiceContract(SessionMode = SessionMode.NotAllowed)]
interface IMyContract
{.................}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
class MyService : IMyContract
{.................}








In this above post I explained you can limit how many instances or sessions are created at the application level

No comments:

Post a Comment