Where WebService stores its variables data?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Car Jakis
    New Member
    • Apr 2011
    • 2

    Where WebService stores its variables data?

    Hi!
    I've got a WebService that stores names of logged users. It is a simple C# List<string> that is private and static and I add some strings to it and read values, using WebService's functions in my WindowsForms client application.

    And my first question is - is it save to keep data in variable? And where that data are stored? Cache, session? I made some tests and it occures to me that one day data where deleted from WebService's memory after several seconds (I tried cache to store data from List<string> but it also looses values after a very short time...) and another day they were alive for many minutes (at least 25 minutes!). Now I don't know who should I blame - my code or the server where is my WebService ;).

    Sorry for my English...
  • TRScheel
    Recognized Expert Contributor
    • Apr 2007
    • 638

    #2
    Im pretty sure its held in the session for that particular user but I could be wrong.

    It is safe to hold it there, but I imagine there might be another method of holding onto who currently has an open session with your website. I would suggest a separate field in an existing users table on your DB or a new table altogether that lists (or reflects) who is online.

    For instance, if you have a table with users/passwords/etc, add a field that has LoggedIn. Set it to true when they are logged in and false when they leave. Have the control on your page that lists who is online use the DB for their reference, not an internal list.

    This comes down to where you want the data and how you want to optimize it. Doing it by the DB will decrease your memory consumption but increase your DB queries, and doing it with a static list<string> will do the exact opposite.

    Im sure there are other, more elegant methods as well

    Comment

    • Sfreak
      New Member
      • Mar 2010
      • 64

      #3
      Car,

      Webservice´s session are a little bit different when compared to asp.net applications.

      To you to store data in sessions in webservices you need to explicit show what session you are working on, sending the session object when you call the webmethod, because webservices dont create proxies or something like that. When you store data in static classes on webservices you are alocating memory on your server machine managed by the IIS. When you record data on static classes on your webservice you must manage it because ALL client machines are sharing this static class because webservices dont create a context for each client connection (I suppose).
      So if you are sharing this class among all your clients be sure that they are behaving exactly the way you want, and you wont lose any data.
      Last edited by Sfreak; Apr 4 '11, 12:57 PM. Reason: English grammar

      Comment

      • TRScheel
        Recognized Expert Contributor
        • Apr 2007
        • 638

        #4
        Yeah, given the behavior of it I would strongly advise against using a webservice for this. After thinking it over I think the better idea would be instead of a column for "LoggedIn" being a boolean, have it be the last time you talked with that user. Then just do a DB query for all users active within the last 10 minutes or so.

        Its been a long time since I've worked with ASPX though so take my advice with a grain of salt.

        Comment

        • Car Jakis
          New Member
          • Apr 2011
          • 2

          #5
          Yes TRScheel, you are right, the option with data base looks great and safe for my data but i tried it and... There were too much queries at the same time :(! The problem is that my client application request service frequently - for example every 0.5 second. Lets say now, that there is about 10 clients application that does it and about 1000 records to manage... I'm afraid it will kill the data base. That is the main reason why I prefere using variables state instead, but I'm still not sure if it is safe, good and elegant ;).

          Sfreak, it is what I really want! :D I need to cache some often-changing data in service memory and share it with all the clients' applications because I want all the users to know the others logged users' names. I'm just curious how long this data will be stored in server machine memory - I suposed that data should be there till I delete them or as long as server is turned on but when I tested my project a few days ago, data were lost after several seconds...

          Comment

          • TRScheel
            Recognized Expert Contributor
            • Apr 2007
            • 638

            #6
            I dont know why I totally forgot about this, but Cache is exactly what you're looking for

            Can read more about it here

            Comment

            Working...