1
votes

I have a WCF Service in which I want to maintain session for my Authentication method.

I have gone through from various articles and applied some of the below changes which are required to maintain session in WCF Service, as WCF not supported Session by default.

1- [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] in svc file.

2- [ServiceContract(SessionMode = SessionMode.Allowed)] in ServiceContract

3- Use the wsHttpBinding as basicHttpBinding not supported Session.

I am using WCFTestClient to call my service. I have checked the config of my TestClient and it is using basicHttpBinding, here is the cause of issue.

I am unable to implement the 3 point in my Service webconfig and also unable to change the config of my TestClient. Can anyone please guide me. Thanks

1

1 Answers

0
votes

To solve this I implemented my own SessionHandler within the service.

  • a thread safe singleton class containing a Dictionary<Guid, SessionData>
  • Service Method: Guid RegisterClient(ClientName clientName) { /* add client to session */ }
  • Service Method: bool UnregisterClient(Guid clientGuid) { /* remove client from session */ }
  • Service Method: void DoThisOnServer(Guid clientGuid) { /* the service functionality */}
  • void CheckTimeout() { /* iterate over dictionary and remove out timed sessions */ }

Hints:

  • SessionData contains ClientName, TimeOfConnection, YourUsefulData
  • ClientName is a placeholder for IP-Adresse or some other initial identificator

Client has to register and all following operations are done only if the provided Guid exists in SessionHandler.