SessionMode Enumeration
Specifies the values available to indicate the support for reliable sessions that a contract requires or supports.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
| Member name | Description | |
|---|---|---|
| Allowed | Specifies that the contract supports sessions if the incoming binding supports them. | |
| Required | Specifies that the contract requires a sessionful binding. An exception is thrown if the binding is not configured to support session. | |
| NotAllowed | Specifies that the contract never supports bindings that initiate sessions. |
Use the SessionMode enumeration with the ServiceContractAttribute::SessionMode property to require, allow, or prohibit bindings to use sessions between endpoints that connect to or support the service contract. A session is a way of correlating a set of messages exchanged between two or more endpoints. For more information about sessions, see Using Sessions.
If your service supports sessions, you can then use the ServiceBehaviorAttribute::InstanceContextMode property to specify the relationship between instances of your service contract implementation and the channel session.
For example, if the SessionMode property is set to SessionMode::Allowed and the ServiceBehaviorAttribute::InstanceContextMode property is set to InstanceContextMode::PerSession, a client can use a binding that supports reliable sessions to make repeated calls to the same service object.
Because a session is a channel-level concept that the application model uses, there is an interaction between the SessionMode enumeration in a contract and the ServiceBehaviorAttribute::InstanceContextMode property, which controls the association between channels and specific service objects.
The following table shows the result of an incoming channel either supporting reliable sessions or not supporting reliable sessions given a service's combination of the values of the ServiceContractAttribute::SessionMode property and the ServiceBehaviorAttribute::InstanceContextMode property.
InstanceContextMode Value | Required | Allowed | NotAllowed |
|---|---|---|---|
PerCall |
|
|
|
PerSession |
|
|
|
Single |
|
|
|
The following code example shows how to use the SessionModeproperty of the ServiceContractAttribute to specify that the IMyService service contract requires bindings that support session state.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.