Demarcating Operations
Sometimes, a sessionful contract has an implied order to operation invocations. Some operations cannot be called first, while other operations must be called last. For example, consider this contract used to manage customer orders:
[ServiceContract(SessionMode = SessionMode.Required)]
interface IOrderManager
{
[OperationContract]
void SetCustomerId(int customerId);
[OperationContract]
void AddItem(int itemId);
[OperationContract]
decimal GetTotal( );
[OperationContract]
bool ProcessOrders( );
}The contract has the following constraints: the client must provide the customer ID as the first operation in the session, or else no other operations can take place; items may be added, and the total calculated, in any order, and as often as the client wishes; processing the order terminates the session, and therefore must come last.
WCF allows contract designers to designate contract operations as operations that can or cannot start or terminate the session using the IsInitiating and IsTerminating properties of the OperationContract attribute:
[AttributeUsage(AttributeTargets.Method)]
public sealed class OperationContractAttribute : Attribute
{
public bool IsInitiating
{get;set;}
public bool IsTerminating
{get;set;}
//More members
}Using these properties may demarcate the boundary of the session; hence I call this technique demarcating operations. During the service load time (or the proxy use time on the client side), if these properties are set to their nondefault ...