Jump to content

Catch Session Timeout Events in LV Web Service

Go to solution Solved by Roryriffic,

Recommended Posts

Hi all,


new to Lava, so (kindly) let me know if I screwed up my post :)


I have a multi-user web application controlled by a LV web service.  I keep track of all the users through the web service > sessions VI's.  This is pretty cool and works really great. I can give each user different levels of authentication, force them to use SSL, track where they go and when throughout the website, etc.


Now what I'd like to do is keep track of when their session expires.  Obviously I can provide a "Logout" link on the client-side which ultimately calls the "Destroy Session" VI, but I can't ensure that all clients will click the link to log out (e.g. how many times do you really sign out of gmail verse just close the browser?!)


What's the best way to catch the session timeout event that is specified during "Create Session" VI?  It appears as if I need a "LV Web Service Request" object to even call the Destroy Session VI, which makes matters much more difficult it seems. Is this even possible?


Thanks for the help

Link to post
  • Solution

Found the answer...  Maybe this is above and beyond, maybe nobody cares, but we're all friends here and I hope this helps somebody in the future...
We can all agree that the easiest way to detect when the user's session ends would be for LV to expose the session timeout event, but LV does not do this (as of 2013sp1).  Furthermore, LV does not provide a mechanism for storing session handles/IDs and later polling them to see if the session still exists.  You can get the ID all day long, but you can do nothing with it (anybody see the two feature requests?).
Thus, you have to get creative on the client side.  I'm using Javascript/jQuery/AJAX on the front-end to talk to the LV web service on the back-end, so that's the answer I'll describe.  Basically, to properly tell when a client's session ends you need to do two things: (1) give the client a [manual] link that will fire your custom "Logout.vi" AJAX method, and (2) you need to [automatically] catch the $(window).unload() event from the client to asynchronously launch that same "Logout.vi" AJAX command.  The $(window).unload() event is from jQuery and will fire when the user closed the browser or navigated away. Here's my pseudo-method to get the job done:

   $(document).ready(function() {

         Sends a message to the server notifying the 
         user navigated away from the page.
         /MyWebService/logout should map to your custom
         web service VI that eventually calls 
         "Destroy Session VI"
      $(window).unload(function() {
         alert("Hey! You're navigating away from my website and \
            and I'm about to tell the server to close your session!");
            type: "GET",
            url: "/MyWebService/logout",
            async: true,
            success: function() {
               // do something on success(?)
               // not much you can do if user navigating away
            error: function() {
               // do something on error(?)
               // not much you can do if user navigating away
         }). // end $.ajax()

      }); // end $(window).unload()

   }); // end $(document).ready()

So, yea, basically you'd put this in your HTML or Javascript file and make sure that your Logout.vi does what you need to to do to clean up the session.  In my case, I'm just logging the time to a database (for information) and destroying the session (for security).


NOTE: If testing in Chrome, Chrome blocks alert() during unload events.


Hope this helps someone

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By Mode_Locked
      My code watches for an event where my Toshiba USB stick is unplugged. If the event does not occur within 30 secs, the code times out. However, in the case that there is no disconnection of the USB stick (no event generated), I can't end the program before the timeout period of 30 sec. Is there a way to end the program before the timeout period? Any help is appreciated. Thanks in advance!
    • By ThomasGutzler
      I'm connecting to a Rigol DZ1000 Oscilloscope via USB and using the :DISP:DATA? ON,0,PNG command to grab a screenshot. Reading out the data in blocks of 65535 bytes until there is no more (see attached vi).
      This normally works fine but yesterday I was getting a timeout error. I fired up IO Trace and got this:
      > 783. viRead (USB0::0x1AB1::0x04CE::DS1ZA201305475::INSTR (0x00000001), "#9000045852‰PNG.......", 65536 (0x10000), 45864 (0xB328)) > Process ID: 0x000039C8 Thread ID: 0x00001760 > Start Time: 13:13:54.1169 Call Duration 00:00:10.4323 > Status: 0xBFFF0015 (VI_ERROR_TMO) You can see that 45864 bytes were received, which is exactly what was specified by the binary data header (45852 data bytes + 11 header bytes + 1 termination char)
      I dumped the reply string into a binary file and set the scope to run so it show something else on the screen. Sure enough the error went away. I also dumped a good result into a file. Then I tried to figure out what the problem may have been but I didn't get anywhere. Any ideas? Sure looks like a bug in VISA read or perhaps an incorrectly escaped reply from the scope?
      It's very easy to "convert" the reply into the screenshot - just remove the leading 15 bytes (4 bytes from WriteBinayFile and 11 bytes from the scope header). And yes, both data files display just fine as PNG. I don't think PNG does internal checksum so byte errors would be hard to spot.
      Any ideas what could have caused that timeout?

    • By _Mike_
      I am running a system with GigE camera with NI framegrabber  in continuous acquisition mode - in which I change some attributes every now and then.
      So far I have been using following scheme to assert I am getting correct image after attribute change:
      change attribute read "Last buffer number" property -> n run IMAQdx get image.vi set to "buffer' and parameter n+2 (+2 being due to the fact that i assumed attribute change arrives to camere during running exposure that will be unaffected by attribute change - hence i needed to discard "next" buffer) Unfortunately I still every now and then acquired image that obviously was aquired with previous attributes (e.g. I've dramatically increased.decreased exposure rate, while acquired image was very similar to previously acquired one). Guessing that it may have something to do with buffers I have increased "magic number" from +2 to +3. It indeed helped, but after longer usage I have discovered, that it only reduced the frequency of the error.
      Hence I needed to design more "bulletproof" solution that will satisfy my timing requirements (stoping and starting acquisition is out of question as it takes more than 100ms what is unacceptable for me)
      I would like to:
      change attribute acquire information from camera that will allow me to fetch image acquired with changed attribute For such purpose I have discovered IMAQdx events - especially "Attribute updated" and "frameDone". Unfortunately, I could not find any detailed documentation about those functions. Therefore I would like to ask you for help to determine when 'Attribute updated" is triggered. Is it when:
      driver receives the command and pushes it to camera? (pretty useless for me as I cannot relate it to any particular exposure) camera confirms getting it (then assuming it arrives during an ongoing exposure, I'll discard "next' image and expect second next to be correct camera confirms applying it (then I assume that next image should be obtained with correct settings) camera confirms it managed to acquire a frame with new parameter (pretty unlikely scenario - but the i'd expect correct image to reside in "last" buffer) Could you help me determine which case is true? Also should I be concerned about the fact that there may be a frame "in transition" between camera and IMAQdx driver which will desynchronize my efforts here?
    • By takanoha
      I am writing an application to update the numeric value given user's input value and depending on the user's input value the program checks if it is greater than 10 if it is greater than 10 then the program waits for 1 second and then will have a popup message says "true".
      My intention was to call the conditional check, printing true every one second if the user's input value is greater than 10; in other words, the case structure was to be called regardless of the event structure in the same loop infinitely.
      But it doesn't seem to work the way I expected. Unless there is user's new input value, getting into the event structure, the program doesn't get to the case structure even though the case structure is in a loop.
      Is there any way to call the case structure not dependent to the event structure but I want to use a shift register for the numerical value and also having an event structure and a case structure in parallel ? 
      Thank you.

    • By MDMCE
      Hello Everyone,
      I have a project that I am working on. It is running on an old machine using Windows XP, and LabVIEW 8.6.1. Our customer has requested that we add the capability to make a call to a web service that they have written. They do not want to upgrade the OS or LV version, so I am trying to find a way to do this in 8.6.1. They have given my the wsdl file to review and it is specifying using the SOAP protocol in a request/response format. The request message, requires 5 pieces of string data from the LabVIEW application. I have never done any web service calls before in any language so I am trying to learn that as I go as well. I have tried searching on the forums on how to do this, but I have not found anything. So I would like to know if there are any VIs in 8.6.1 to support this kind of request. If there are, can someone please tell me which VIs/pallet to use and some guidance on how to use them?
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.