Demarcation of Operations
Demarcation is to annotate service operations by some special attribute to determine the first and last operation in their execution order. Consider a service having 4 methods/operations named-
SignIn()
, GetDetails()
.TransferFund()
and SignOut()
. In such a scenario, a user must be signed in and then try to fetch details and do transfer. If user signs out, then he should not be allowed for further requests until he signs in. To configure such type of execution order, Demarcation is required. There are two attributes:IsInitiating
(Default -True
)IsTerminating
(Default –False
)
These attributes decide which operation should be called first and which should be last? For the above four operations, following can be one possible sequence:
[OperationContract(IsInitiating = True)]
Bool SignIn()
[OperationContract(IsInitiating = false)]
String GetDetails()
[OperationContract(IsInitiating = false)]
Bool TransferFund()
[OperationContract(IsInitiating = false, IsTerminating = True)]
Bool SignOut()
Here initiation and termination refers to a session which is mandatory for demarcation, as service needs to know whether client has followed the particular sequence or not. Here operation 2,3 and 4 are set to
IsInitiating = false
so cannot be called first but can be called after an Isinitiating = True
operation is called. Similarly, Operation 4 is annotated as IsTerminating = True
that’s why when it is called, it terminates the session (along with underlying channel) and then client cannot make further calls until a fresh proxy is created and an IsInitiating = True
operation is called. To use demarcation, the following configuration is necessary:- A session supportive binding
SessionMode
set toRequired
When
IsTerminating
operation is called,WCF discards the channel and never accepts further messages from it. If an operation is not decorated explicitly with any of these attributes, then default value of these attributes will be applicable to it.
That’s all for now.
At last, just recapitulate once - There are 3 things to remember for WCF session:
Sessionful
bindingSessionMode
service contractInstanceContextMode
service behavior
Demarcation defines first and last operation in execution order.
WCF session is somewhat different than ASP.NET sessions in the following ways as inWCF:
- Sessions are created and terminated by clients.
- Server does not use session to store some general data.
- Session does not heavily rely on Session Id, a group of messages having particular field in their header or body can also be considered part of session.
- Session Id may not be same at client and server.
Hope this small article has given you some brief idea about WCF session and now you can feel some base for further reading. Please do some experiments on your own and refer to MSDN for in depth analysis of the concept.
Please let me know if something is missing or needs correction as it will be helpful for all of us.
No comments:
Post a Comment