Showing results for 
Search instead for 
Did you mean: 

Catch Web Service Session Timeout Event

Go to solution

Hi all,


I have a LV Web Service communicating to a web-client (Chrome, IE, FF, etc).  The user logs in to the server and I create a new session for him using Create Session VI.  One of the inputs to this function is a timeout value (default 60000ms).  The behavior of the sessions is such that if the user does not initiate a web service request (GET/POST/PUT/etc) within the timeout period, then the session is automatically destroyed by the web service.  That's what I want, fantastic.


My question is how can I detect when the session timeout happens? Another way to say it, how can I detect when the user's session is automatically destroyed?  


What I've Tried:

  • Of course I can provide a "logout" link to the user that ultimately calls "Destroy Session" VI, but I cannot rely on the user to actually click this link (e.g. do you really explicitly log out of gmail or just close your web browser?)
  • I thought the only way to do this would be to save the session ID cookie returned from Create Session VI and then poll that ID to see if the session still exists (Check If Session Exists VI).  If the session doesn't exist, well then I know it timed out or the user destroyed it manually.  However, even if I save the cookie ID, I don't see where I can actually use it anywhere (especially not Check If Session Exists VI). It just seems like worthless data to the sessions palette.

Is this possible?




0 Kudos
Message 1 of 4

Hi Rory,


Your second suggestion using the Check If Session Exists VI should work. You can directly wire the 'LabVIEW Web Service Request out' terminal on the Create Session VI to the 'LabVIEW Web Service Request in' terminal on Check If Sessions Exists VI. This way you do not have to worry about reading the cookie.

Thomas N.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
Accepted by Roryriffic

Sorry, Thomas, but that's not going to work.  Think about it -- you're not going to get a web service request during timeout. You ONLY get a web service request when the client actually requests something.  The client does not do this during a timeout; it just... times out... thus, there's no node on the block diagram to check because there's no block diagram... get it?


No worries, though, I found the solution [read: workaround], even though LV cannot do this (as of 2013sp1).  


The easiest way to detect when a user's session expires/times out would be for LV to expose this as an event in the web service. The next approach would be for LV to accept a cookie ID as an input, and then provides information about that session (ie does the session exist).  I smell two feature requests... 


But because LV cannot do these things (or doesn't expose them to the developer), then you have to get creative on the client side.  Since I'm using Javascript/jQuery/AJAX on my front-end, then it is possible for me to detect when the client navigates away from the page or closes the browser.  This is $(window).unload() in jQuery.  Then, I can catch that event and fire an asynchronous AJAX command to one of my web service VI's that will ultimately call the "Destroy Session" VI. 


For more info check it out here:


Hope this helps somebody.  

0 Kudos
Message 3 of 4

Four years later, I'm facing the exact same problem as described by the author of the first post.


However, I can't use his workaround solution as my client implementation is different.


Does someone know how to do this?

0 Kudos
Message 4 of 4