WCF sessions are different than the session object in ASP.NET , support different behaviors, and are controlled in
different ways.WCF sessions are very different from ASP.NET Sessions. In short,
ASP.NET Sessions are:
To configure sessions in WCF, one should know the following three elements:
ASP.NET Sessions are:
- Always server-initiated.
- Implicitly unordered.
- Provide a way to preserve data across multiple requests.There is unique session id generated at the server and passed back and forth between client and server via URL or cookies.
- Initiated and terminated by the calling application (WCF Client).
- Ordered message delivery.
- Sessions correlate a group of messages into a conversation.This correlation depdending upon the binding can be taken care at message or transport level.
- No data storage is involved with WCF Session.
To configure sessions in WCF, one should know the following three elements:
Binding
– Because all bindings do not support sessions. Only WS-*, NetTcpBinding andNetNamedPipeBinding
have session support so selection of appropriate binding is necessary.SessionMode
– This service contract specifies service’s possible expectation for session from incoming client request. It has three self describing values:*)Allowed
– Service can accept sessionful clients as well as sessionless.*)Required
– Service will entertain only those clients who have session, sessionless client cannot connect to service.*)NotAllowed
– Service can interact only with sessionless clients. Just opposite toRequired
.InstanceContextMode
– This is a service behavior that controls instantiation of actual service class. It has the following values:*)PerCall
– Each request made to server will be served by a new instance of service class.*)PerSession
– A Session will have its dedicated service instance and all requests pertaining to the session will be served by that instance only. All sessions will have their individual dedicated service instances.*)Single
–All requests to the service will be served by a single unique instance of service class.
1) Sessionful
binding. (
<endpoint address="http://localhost:750" binding="wsHttpBinding"
contract="wcfservice.Iservice" name="wcfSessionTest"/>
)2) SessionMode
service contract. (
[ServiceContract(SessionMode = SessionMode.Allowed)]
public interface Iservice
{
//some code…
}
)
3) InstanceContextMode
service behavior.
([ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class serviceclass : Iservice
{ // some code… }
)
No comments:
Post a Comment