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
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

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

[WebMethod(EnableSession = true)]
public String DoNothing()
// 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
localhost.CellSearchService svc1 = new
svc1.CookieContainer = cc;
localhost.CellSearchService svc2 = new
svc2.CookieContainer = cc;
svc1.DoNothingCompleted += new
WebSvcTester.localhost.DoNothingCompletedEventHand ler(pr1.svc_DoNothingCompleted);
svc2.DoNothingCompleted += new
WebSvcTester.localhost.DoNothingCompletedEventHand ler(pr2.svc_DoNothingCompleted);

void svc_DoNothingCompleted(object sender,
WebSvcTester.localhost.DoNothingCompletedEventArgs e)

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.