Session state

Discussion in 'ASP .Net Web Services' started by Alex, Apr 21, 2010.

  1. Alex

    Alex Guest

    I have a WS that contains multiple classes and web methods. We need to keep
    track of execution times. To do this, I created a class with two properties,
    one of them is a unique "ThreadId" which is a simple random string. The
    reason for this is that we need to keep track of execution times through all
    methods. E.g. GetUser() calls a Login() method, and then calls the GetUser
    data access method, then calls a DataSetToJSON method etc, so the theory is
    that when we query the execution times, we can see the stack trace and group
    it by the ThreadId.

    The problem is that when we have multiple hits to the WS, the ThreadId is
    being "shared" among different connections. I assumed that each new WS call
    will get it's own ThreadId, but this is not the case.

    How can I create this object containing the threadId for each specific

    Alex, Apr 21, 2010
    1. Advertisements

  2. Alex

    Alex Guest

    An Example is when User1 calls a web method, I generate a "ThreadId" string
    and log that in the database. When User2 calls a web method in the same
    class, it too generates a different ThreadId. But in some cases, when traffic
    is high, it looks like the same ThreadId is being used by different users.
    Alex, Apr 21, 2010
    1. Advertisements

  3. Alex

    Patrice Guest

    How do you create those "thread id" ? You could likely unit test your thread
    id generator to see if you get duplicates...

    AFAIK the session state module creates session ids by creating a guid that
    is then turned into a string (base 64 encoded ?). You could perhaps use
    something similar. Strictly speaking, uniqueness is not enforced but if you
    ever come accross a collision you are really out of luck (i.e. something
    like getting the same value twice when you have 10 power 36 possible

    Also it is still possible that you have some kind of programming error
    (notably using C# static or VB shared data). How do you keep this thread id
    accross calls ?
    Patrice, Apr 21, 2010
  4. Alex

    Alex Guest

    The string generation is pretty unique. But I think the issue is in the code.
    I'm using InvokeMember to execute methods (used for version control) and I
    think it's none-managed code, and coupled with the fact that I'm using a
    static data object, the results are that some "connections" use the same

    I'm about to test this and will update the thread.

    Thanks for the reply.
    Alex, Apr 21, 2010
  5. Alex

    Alex Guest

    That was it. InvokeMember makes the class loose state. There goes a day that
    I'll never get back...
    Alex, Apr 21, 2010
  6. Alex

    Patrice Guest

    Yes, static data are shared by the whole application. The point to keep in
    mind is that a web application is a *single* application used by multiple
    users at the same time so all static data are shared accross those users...
    Patrice, Apr 22, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.