Thursday 7 July 2016

What is InstanceContext or Instance mode in WCF?.



Instancing behavior controls how instanceContext is created in response to incoming message. In other way we can say, WCF InstanceContext dictates how instance is created.

              There are different ways by which you can create WCF Instance.
1.)    Per Call: - A new instance or service object is created for each client request.
Example:-
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
public class Service : IService
{

}

2.)    Per Session:- A new Instance or service object is created for each new client session and maintained for the lifetime of that session.
Example:-
[ServiceBehavior(InstanceContextMode=InstanceContextMode. PerSession)]
public class Service : IService
{

}

3.)    Single:- A single instance or service object handles all client request for the lifetime of the application.
Example:-
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class Service : IService
{

                   }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.