.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Jean Paul
SP
satyapriyanayak
Ashutosh Jha
Simon Robert VoIP

Home >> Articles >> WCF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Session ID in WCF

Posted By:Dhananjay Kumar       Posted Date: February 22, 2010    Points: 25    Category: WCF    URL: http://www.dhananjaykumar.net  

Session Id in WCF. This article is based on Instance Management in WCF. This article will explain how to work with Session ID in WCF. This article will give theoretical introduction and explanation of coding sample also. It will explain 2 full coding sample that how to work with Session ID in WCF.
 

Objective

This article is based on Instance Management in WCF. This article will explain how to work with Session ID in WCF. This article will give theoretical introduction and explanation of coding sample also. It will explain 2 full coding sample that how to work with Session ID in WCF.


Note: There is no any attached code with this article because; I have amended same sample to give different demonstration. I am sorry for that, but once you will go through article, you will able to understand the concept behind.

The Session ID in WCF
image1.gif


  1. Every session has a unique Session ID.
  2. Both client and service can obtain and use the Session ID.
  3. The Session ID is in form of GUID.
  4. The main use of Session ID is in logging.
    image2.gif
Session ID at Server side
  1. Every Service operation has an operation call context accessible via the operational class.
  2. A Service can obtain a reference to the operation context of current method via the Current static method of the OperationConext class.
image3.gif
Session ID at client side

image4.gif

Fetching Session ID at client for a Per-Session configured service (Sample #1)
In below code sample
  1. Service is configured as Session full service.
  2. SessionMode of contract of service is set to Required.
  3. Client is referencing the service and creating different proxies.
  4. Expected output is ,

    image5.gif
Service Interface (Contract)

image6.gif


Service

image7.gif

Client

image8.gif

Output

image9.gif

image10.gif

Comparing Session ID at client and Service for a Per-Session configured service (Sample #2)

In below code sample
  1. Service is configured as Session full service.
  2. SessionMode of contract of service is set to Required.
  3. Service is exposing one Operation Contract, which is returning Session ID for a particular operation context.
  4. Client is creating a Proxy and fetching the session ID.
  5. There is a comparison between Session Id returned by service and Session Id fetched by client for a particular session. Whether both session ID is same or not.
Service Interface (Contract)

image11.gif

Service


image12.gif

Client

image13.gif

Output

image14.gif

image15.gif
Conclusion

This article explained about, Session ID in WCF. This article gave theoretical introduction and explanation of coding sample also.
 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend