Suggested Videos
Part 39 - PerSession WCF services
Part 40 - How to retrieve the sessionid in WCF service and in the client application
Part 41 - Single instance context mode in WCF
In this video, we will discuss the significance of SessionMode Enumeration in WCF.
This is continuation to Part 41. Please watch Part 41 before proceeding.
Use SessionMode enumeration with the Service Contract to require, allow, or prohibit bindings to use sessions. SessionMode enum has the following members.
Allowed : Service contract supports sessions if the binding supports them. This is the default if we have not explicitly specified the SessionMode on Service contract.
NotAllowed : Service contract does not support bindings that initiate sessions.
Required : Service contract requires a binding that supports session.
Let's look at 2 examples. We will work with the same example, that we worked with in Part 41.
Example 1: Set the service InstanceContextMode to Single and SessionMode to Allowed.
If we use basicHttpBinding that does not support sessions, the service still works but without session.
On the other hand if we use, netTcpBinding that support sessions, the service gets a session, and continue to work as a singleton service.
Example 2: Now change SessionMode to Required.
If we use, netTcpBinding that support sessions, the service gets a session, and continue to work as a singleton service.
On the other hand, if we use basicHttpBinding that does not support sessions, the following exception is thrown
System.InvalidOperationException: Contract requires Session, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it.
The following MSDN link, shows all the possible combinations of Service Instance Context Mode values and SessionMode enumeration values, and the end result of using each of these combinations with bindings that does and does not support sessions.
http://msdn.microsoft.com/en-us/library/system.servicemodel.sessionmode(v=vs.110).aspx
Part 39 - PerSession WCF services
Part 40 - How to retrieve the sessionid in WCF service and in the client application
Part 41 - Single instance context mode in WCF
In this video, we will discuss the significance of SessionMode Enumeration in WCF.
This is continuation to Part 41. Please watch Part 41 before proceeding.
Use SessionMode enumeration with the Service Contract to require, allow, or prohibit bindings to use sessions. SessionMode enum has the following members.
Allowed : Service contract supports sessions if the binding supports them. This is the default if we have not explicitly specified the SessionMode on Service contract.
NotAllowed : Service contract does not support bindings that initiate sessions.
Required : Service contract requires a binding that supports session.
Let's look at 2 examples. We will work with the same example, that we worked with in Part 41.
Example 1: Set the service InstanceContextMode to Single and SessionMode to Allowed.
If we use basicHttpBinding that does not support sessions, the service still works but without session.
On the other hand if we use, netTcpBinding that support sessions, the service gets a session, and continue to work as a singleton service.
Example 2: Now change SessionMode to Required.
If we use, netTcpBinding that support sessions, the service gets a session, and continue to work as a singleton service.
On the other hand, if we use basicHttpBinding that does not support sessions, the following exception is thrown
System.InvalidOperationException: Contract requires Session, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it.
The following MSDN link, shows all the possible combinations of Service Instance Context Mode values and SessionMode enumeration values, and the end result of using each of these combinations with bindings that does and does not support sessions.
http://msdn.microsoft.com/en-us/library/system.servicemodel.sessionmode(v=vs.110).aspx
Venkat sir,
ReplyDeletePlease discuss security in WCF.
I have a question. If I host a WCF service and I want only some selected users to access that. How can I do that?
Thanks
Venkat sir
ReplyDeleteplease keep the source code files of examples to download what examples you used to explain to us