Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Part 40 - How to retrieve the sessionid in WCF service and in the client application

Suggested Videos
Part 37 - PerCall instance context mode in WCF
Part 38 - PerSession instance context mode in WCF
Part 39 - PerSession WCF services



In this video, we will discuss retrieving sessionid in WCF service and in the client application

This is continuation to Part 39. Please watch Part 39 before proceeding. We will work with the same example, that we worked with in Part 39.



In order to send messages from a particular client to a particular service instance on the server, WCF uses SessionId
retrieving sessionid in WCF

There are different types of sessions in WCF. We will discuss these in a greater detail in a later video session.

To retrieve SessionId from the client application use 
procyClassInstance.InnerChannel.SessionId property

To retrieve SessionId from the WCF service use 
OperationContext.Current.SessionId

The client-side and service-side session IDs are corelated using the reliable session id. So, if TCP binding is being used with reliable sessions disabled then the client and server session id's will be different. On the other hand, if reliable sessions are enabled, the session id's will be same.

Enable reliable sessions using the binding element as shown below
<bindings>
  <netTcpBinding>
    <binding name="netTCP" receiveTimeout="00:00:10">
      <reliableSession enabled="true"/>
    </binding>
  </netTcpBinding>
</bindings>

With wsHttpBinding, irrespective of whether reliable sessions are enabled or not, the session id's will be same.

wcf tutorial

No comments:

Post a Comment

It would be great if you can help share these free resources