Introduced
WCF (Windows communication Foundation)-session state:
ServiceContract
· Sessionmode.allowed-Specifies that the contract also supports sessions (default) When incoming binding support sessions
· SessionMode.Required-Specifies that the contract requires session binding. If the binding is not configured to support sessions, an exception is thrown
· Sessionmode.notallowed-Specifies that the contract will never support binding to start a session
OperationContract
· IsInitiating-Gets or sets a value that indicates whether the method implements an operation that can initiate a session on the server, if a session exists.
· IsTerminating-Gets or sets a value that indicates whether the service operation causes the server to close the session after it sends a reply message, if one exists.
Example
1. Service
IHello.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text;
Using System.ServiceModel; Namespace WCF. servicelib.sessionmanagement {/**////<summary>///interface to demo session state///</summary>notallowed///<remark S>///SessionMode-Gets or sets whether the session///sessionmode.allowed is allowed, disallowed, or required-Specifies that the contract also supports sessions (default)///when an incoming binding support session is available Sessionmode.requi Red-Specifies that the contract requires session binding. If the binding is not configured to support a session, an exception is thrown///sessionmode.notallowed-Specifies that the contract will never support the binding///of the start session </remarks> [ServiceContract (SessionMode = sessionmode.required)] public interface Ihello {/**////<summary>///initialization session///</summary
>///<remarks>///isinitiating-Gets or sets a value that indicates whether the method implements an operation that can initiate a session on the server, if a session exists.
IsTerminating-Gets or sets a value that indicates whether the service operation causes the server to close the session after it sends a reply message, if one exists.
</remarks> [OperationContract (isinitiating = true, IsTerminating = False)] void startsession ();
/**////<summary>///End Session///</summary> [OperationContract (isinitiating = False, IsTerminating = true)] void stopsession (); /**////<summary>///Get counter results///</summary>///<returns></returns> [Operationcon
Tract (isinitiating = false, IsTerminating = false)] int Counter (); /**////<summary>///Access SessionID///</summary>///<returns></returns> [operatio
Ncontract (isinitiating = False, IsTerminating = False)] string GetSessionID (); }
}