Blocking problem/bug with enableSession=true and asynchronous web service calls?

Discussion in 'ASP .Net' started by Jonathan Trevor, Feb 12, 2004.

  1. Hi,

    I've found what appears to be a bug with ASP.NET web service method
    invocation - making it impossible to invoke and get the result of a
    synchronous web call after an asynchronous call has been made if both are
    using sessions.

    Heres an example for two calls in the web service, the first is expected to
    be executed asynchronously by the client and the second to get the progress
    of the first while it is executing:

    [SoapRpcMethod(RequestNamespace="",ResponseNamespace="")]
    [WebMethod(EnableSession = true, Description="")]
    public MyResult DoLongTask(string progressHandle)
    {
    try
    {
    Thread.Sleep(7000);
    return new MyResult();
    } catch (Exception ex) { return null; }
    }

    static int count=0;
    [SoapRpcMethod( RequestNamespace="",ResponseNamespace="")]
    [WebMethod (EnableSession = true, Description="")]
    public ProgressEvent GetProgress(string progressHandle)
    {
    try
    {
    Debug.WriteLine(DateTime.Now.ToLongTimeString()+ " Trying to get
    progress for "+progressHandle);
    ProgressEvent pe = new ProgressEvent(count+=10);
    if (count==100) count=0;
    return pe;
    } catch (Exception ex) { return null;}
    }

    I stripped the calls down to almost nothing, removing the progress updating
    and sharing to try and isolate the cause of a strange problem in the client:

    e.g.
    MyService ap = new MyService();
    ap.CookieContainer = new CookieContainer();
    ap.Login("blah");
    string handle = Guid.NewGuid().ToString("N");
    System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString()+" FORM1:
    About to do long task");
    ap.BeginDoLongTask(handle);
    System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString()+" FORM1:
    Back from do long task begin call");
    ProgressEvent e = null;
    bool done = false;
    while (!done)
    {
    try
    {
    System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString()+"
    FORM1: Getting progress");
    e = ap.GetProgress(handle);
    System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString()+"
    FORM1: Got progress");
    }
    catch (Exception ex)
    {
    System.Diagnostics.Debug.WriteLine(ex.Message);
    }
    if (e!=null) {
    Debug.WriteLine(e.percentComplete);
    if (e.percentComplete==100) done = true;
    }
    Application.DoEvents();
    }
    }

    What you'd expect is that the async call will return immediately and then
    for the GetProgress calls to quickly count to 100. That isn't what happens.

    The BeginDoLongTask call does complete immediately but there is a 7 second
    gap between the time printed by "FORM1: About to do long task" and the
    return value from that - which should be almost instant. That gap is EXACTLY
    the same as the sleep and you can play with that figure to see it's the
    same. Further, the very first writeline in the GetProgress call on the
    server ("Trying to get progress for ") DOES NOT EXECUTE until the
    *asynchronous* call on the server has finished. Once the first "blocked"
    GetProgress call succeeds the remaining GetProgress calls work as expected.

    This is all really messed up.

    However, the "cure" (or at least workaround) after two confused days is to
    take "enableSession=true" out of either of the GetProgress or DoLongTask
    methods (or make the DoLongTask OneWay=true). Then you get the expected
    behavior: the GetProgress calls quickly count to 100 regardless of what is
    happening (what sleep) in the DoLongTask call.

    So whats going on here? Am I doing something really wrong? Why should the
    "enableSession" flag cause this incorrect behaviour? And how can I actually
    use the session in both methods?

    Jonathan
    Jonathan Trevor, Feb 12, 2004
    #1
    1. Advertising

  2. Jonathan Trevor

    lonevvolf

    Joined:
    Jul 31, 2006
    Messages:
    3
    Did you ever find a solution to this? I have the exact same problem!
    lonevvolf, Jul 31, 2006
    #2
    1. Advertising

  3. Jonathan Trevor

    PeteSmith

    Joined:
    Apr 18, 2007
    Messages:
    2
    Also having the same issue? Any solutions or work arounds? :x
    PeteSmith, Apr 18, 2007
    #3
  4. Jonathan Trevor

    lonevvolf

    Joined:
    Jul 31, 2006
    Messages:
    3
    It is apparently not possible to give access to the Session object, and also to use the calls asynchronously.
    lonevvolf, Apr 18, 2007
    #4
  5. Jonathan Trevor

    PeteSmith

    Joined:
    Apr 18, 2007
    Messages:
    2
    Well, I am able to call the async method with sessions enabled but the problem comes if I make a sync call while the async one is still in progress. How did you get around the problem?
    PeteSmith, Apr 18, 2007
    #5
  6. Jonathan Trevor

    lonevvolf

    Joined:
    Jul 31, 2006
    Messages:
    3
    The only solution I had found to the whole problem was removing any dependency on Session state in the calls...not really a great solution, though.
    lonevvolf, Apr 18, 2007
    #6
  7. Jonathan Trevor

    sahar

    Joined:
    Nov 5, 2010
    Messages:
    1
    Has anyone find a solution of this problem yet? :)...
    sahar, Nov 5, 2010
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zg_yuan
    Replies:
    0
    Views:
    380
    zg_yuan
    Aug 25, 2003
  2. =?Utf-8?B?VHJvdHNreQ==?=

    ASP.Net with Asynchronous Web Service calls

    =?Utf-8?B?VHJvdHNreQ==?=, Apr 30, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    4,566
    =?Utf-8?B?VHJvdHNreQ==?=
    May 3, 2004
  3. bdb112
    Replies:
    45
    Views:
    1,341
    jazbees
    Apr 29, 2009
  4. Jonathan Trevor
    Replies:
    1
    Views:
    289
    Sami Vaaraniemi
    Feb 12, 2004
  5. MikeM

    EnableSession going bye-bye in ASP.NET 2.0?

    MikeM, Mar 30, 2005, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    137
    MikeM
    Mar 31, 2005
Loading...

Share This Page