469,575 Members | 1,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

Session access in web service locks the multithreading

I have a problem - if I access the session in Web Service, as soon as I
store
anything in it, requests are no longer running in parallel - instead,
they are
queued and executed sequentially. Here is an example (ASP.NET 2.0, VS
2005).

Web service method (web service is a regular asmx):

[WebMethod(EnableSession = true)]
public String DoNothing()
{
Thread.Sleep(10000);
// HttpContext.Current.Session["initvar"] = 123;
return HttpContext.Current.Session.SessionID;
}

Client (console application with web reference):

class Program
{
static void Main(string[] args)
{
Program pr1 = new Program();
Program pr2 = new Program();
System.Net.CookieContainer cc = new
System.Net.CookieContainer();
localhost.CellSearchService svc1 = new
localhost.CellSearchService();
svc1.CookieContainer = cc;
Console.WriteLine(svc1.DoNothing());
localhost.CellSearchService svc2 = new
localhost.CellSearchService();
svc2.CookieContainer = cc;
svc1.DoNothingCompleted += new
WebSvcTester.localhost.DoNothingCompletedEventHand ler(pr1.svc_DoNothingCompleted);
svc2.DoNothingCompleted += new
WebSvcTester.localhost.DoNothingCompletedEventHand ler(pr2.svc_DoNothingCompleted);
svc1.DoNothingAsync();
svc2.DoNothingAsync();
Console.In.ReadLine();
}

void svc_DoNothingCompleted(object sender,
WebSvcTester.localhost.DoNothingCompletedEventArgs e)
{
Console.WriteLine(e.Result);
}
}

See that first call is sync, and next 2 are async. If in web service
method I have this line commented out:

// HttpContext.Current.Session["initvar"] = 123;

then async calls are processed in parallel, and for all 3 calls I get
different session ids. But if I uncomment it, async calls are executed
sequentially, and all 3 session ids are the same.

Looks like as soon as something is stored in a session (thus, session
is actually used), something in .NET framework prevents requests from
multithreading. Can I make it not so intelligent and leave this
decision to me? I will take care of threads synchronization myself.

Jul 12 '06 #1
0 975

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Billy Jacobs | last post: by
7 posts views Thread by ehendrikd | last post: by
3 posts views Thread by Mark | last post: by
7 posts views Thread by Thomas Nielsen [AM Production A/S] | last post: by
11 posts views Thread by Glenn | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.