09-10-2014 02:40 PM
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:
Is this possible?
Thanks,
Rory
Solved! Go to Solution.
09-11-2014 04:56 PM
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.
09-11-2014 05:25 PM - edited 09-11-2014 05:26 PM
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:
http://lavag.org/topic/18490-catch-session-timeout-events-in-lv-web-service/
Hope this helps somebody.
08-13-2018 08:48 AM
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?