0

I am working on a c# project where I have developed a web service. It connects to a card reader device. When connection is established it creates a session id. When one session id is created I am supposed to kind of lock the device and stop making any more sessions until the current session is released.

When I create a session with the device I am storing the session id in a private variable. I made my program to check for this variable before creating next session. But when I make next call to the web service to create another session it doesn't contain the variable value and creates another session for me.

I am confused as what to do. Is there any way to save the data which can be used to cross check in next calls to the web service? Cookies or registry updates? any solution please..

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Newbee
  • 1,379
  • 2
  • 16
  • 36
  • What kind of program is this? A Windows Forms program or an ASP.NET program? In particular, if it's a program that gets multiple users, then a `static` will be shared across all users. If it gets multiple threads, then the `static` will be accessed by multiple threads at the same time, which is probably not what you wanted. – John Saunders Feb 19 '13 at 01:47
  • Actually this is what I want. Once the variable is set to a session id it wont allow any other device to connect to the reader. Until the current session is released. (When release happen I will reset the variable.) This will work even if the device gets multiple requests. Once I release the device it will be again open for new session. – Newbee Feb 19 '13 at 10:23

2 Answers2

1

Most of what you need is here. For true persistence, you should probably store this in a database of some sort so that you are not beholden to process specific persistence.

Community
  • 1
  • 1
Justin Pihony
  • 66,056
  • 18
  • 147
  • 180
  • Awesome Justin... I just made that variable static and its working fine for me... Thanks a lot... :D – Newbee Feb 18 '13 at 21:22
-1

I think what you want is the Instance Manager for your webservice. It's not too terribly difficult to implement and would accomplish what you're attempting to do.

Here's a link: http://msdn.microsoft.com/en-us/magazine/cc163590.aspx

OnResolve
  • 4,016
  • 3
  • 28
  • 50
  • Hi, I just changed the variable to static and its working fine.. Thanks for your response.. :) – Newbee Feb 18 '13 at 21:28