WCF supports the following Session states (and definition):
1. Per Call [InstanceContextMode.PerCall]: Use this option if you would like a new Session ID to be assigned to a user for every new call into the Service. This is not a good option for our needs as we would like to track the balance from call-to-call for a specific user.
2. Per Session [InstanceContextMode.PerSession]: Use this option if you’d like to assign the user a single Session ID, which will be used to track information from call-to-call. WCF will ensure that each user will get a separate Session ID.
3. Single [InstanceContextMode.Single]: This option establishes one Session ID for all clients to use. This is a little different then “Shareable” in that Shareable has different Session ID’s that you can access between clients, whereas “Single” has only one Session ID that everyone uses.
One of the nice features that WCF supports within Sessions is the ability to specify which methods can initialize a Session and which methods can alternatively terminate a session. This can be done by adding parameter in the [OperationContract]Attribute. Our choices are:
1. IsInitiating=True/False: You can set this to True if you want a call to a method to initiate the Session (i.e., get an assigned Session ID for the user), or False if it should not initiate a session.
2. IsTerminating=True/False: You can set this option to True if you would like a call to a method to Close the Session and release the Session ID, or False, if it should never do so.
You can also do a combination of these choices for a specific method, which would look like this:
[OperationContract(IsInitiating=True, IsTerminating=True]
public void Foo()
Which would cause a Session ID to be created and terminated within the function Foo().
Or,
[OperationContract(IsInitiating=True, IsTerminating=False]
public void Foo()
Which would cause a Session Id to be created by function Foo(), but the termination would happen in another function, or by a Session Time Out value.
The default behavior is
IsInitiating=True, IsTerminating=False(if you don’t change the parameter at all).