By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,600 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,600 IT Pros & Developers. It's quick & easy.

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

P: n/a
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="",ResponseNamespac e="")]
[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.To LongTimeString()+" FORM1:
About to do long task");
ap.BeginDoLongTask(handle);
System.Diagnostics.Debug.WriteLine(DateTime.Now.To LongTimeString()+" FORM1:
Back from do long task begin call");
ProgressEvent e = null;
bool done = false;
while (!done)
{
try
{
System.Diagnostics.Debug.WriteLine(DateTime.Now.To LongTimeString()+"
FORM1: Getting progress");
e = ap.GetProgress(handle);
System.Diagnostics.Debug.WriteLine(DateTime.Now.To LongTimeString()+"
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
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.