views:

299

answers:

2

We have a .net asmx web service that gets called from javascript (using ASP.Net AJAX), and requires access to Session.

[WebMethod(true)]
public string DoSomethingOnTheServer() { }

We're running into the problem of session being locked on a read/write request. Is there any way to mark a web service method as requiring read-only access to Session?

Thanks!

A: 

According to the MSDN documentation of the WebMethod Attribute there are several possible properties, so I'm not sure what the 'true' value in your WebMethod Attribute going to do.

Have you tried:

[WebMethod(EnableSession=true)]

According to this document that should give you full access to the session.

PhillFox
The problem is that method allows both read and write access...I'm looking for a way to just turn on read access (turning on write access causes blocking when you have multiple simultaneous requests). However, I don't believe there is a way.
Jonas
Ah ha, now I see...Now that I've done a little more searching it doesn't make much sense that you can set a Page to have read only access, but not a Web Service.What if you put the WebMethods in a aspx page (exposed as WebMethods) and set the page's EnableSessionState property to ReadOnly?It isn't the best solution, but it might work.
PhillFox
A: 

This http://msdn.microsoft.com/en-us/library/aa480509.aspx page seems to suggest that the answer is "no" - you cannot mark a WebSerivce as having EnableSessionState=ReadOnly.

If you are making simultaneous Web service calls from the same process, the requests will be serialized at the server so that only one will execute at any one time. Unlike .ASPX pages that have support for read-only access to the HttpSessionState object, which allows for simultaneous processing of multiple requests, there is no such capability with ASP.NET Web services. All Web method calls with sessions enabled have read/write access and will be serialized within each session.

Warning: That article is old (2002).

Chris F