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

J

Jonathan Trevor

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
 
Joined
Jul 31, 2006
Messages
3
Reaction score
0
It is apparently not possible to give access to the Session object, and also to use the calls asynchronously.
 
Joined
Apr 18, 2007
Messages
2
Reaction score
0
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?
 
Joined
Jul 31, 2006
Messages
3
Reaction score
0
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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top