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
-
Every session has a unique Session ID.
-
Both client and service can obtain and use the Session ID.
-
The Session ID is in form of GUID.
-
The main use of Session ID is in logging.
Session ID at Server side
-
Every Service operation has an operation call context accessible via the operational class.
-
A Service can obtain a reference to the operation context of current method via the Current static method of the OperationConext class.
Session ID at client side
Fetching Session ID at client for a Per-Session configured service (Sample #1)
In below code sample
-
Service is configured as Session full service.
-
SessionMode of contract of service is set to Required.
-
Client is referencing the service and creating different proxies.
-
Expected output is ,
Service Interface (Contract)
Service
Client
Output
Comparing Session ID at client and Service for a Per-Session configured service (Sample #2)
In below code sample
-
Service is configured as Session full service.
-
SessionMode of contract of service is set to Required.
-
Service is exposing one Operation Contract, which is returning Session ID for a particular operation context.
-
Client is creating a Proxy and fetching the session ID.
-
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)
Service
Client
Output
Conclusion
This article explained about, Session ID in WCF. This article gave theoretical introduction and explanation of coding sample also.