Instance Management in WCF Part # 4

Objective

This article is part # 4 of 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.

Part # 1 of this series could be found Part 1
Part # 2 of this series could be found Part 2
Part # 3 of this series could be found Part 3

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.

Up Next
    Ebook Download
    View all
    Learn
    View all