472,143 Members | 1,657 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

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 1031

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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.