Webservice and session - 05-10-2006 , 03:20 AM
I have a web-service with a web-method where sessionstate=false.
The web method calls a method in another assembly.
Also I have a web-method where sessionstate=true which calls the same method
in the other assembly.
Here I can always access HttpContext.Current, but how do I determine if I
can access HttpContext.Current.Session?
It's in 1.1 framework.
RE: Webservice and session - 05-10-2006 , 08:58 PM
Thank you for posting.
As for the SessionState setting for ASP.NET webservice, it is a webmethod
level setting (through the WebMethodAttribute), so there is not directly
property for us to check this in the webservice class. However, if you do
want to check certain WebMethod's SessionState setting, you can consider
using the Reflection api to query the "WebMethodAttribute" attribute. For
MethodInfo mi = this.GetType().GetMethod("HelloWorld",
object objs = mi.GetCustomAttributes(typeof(WebMethodAttribute),
if (objs != null && objs.Length >0)
WebMethodAttribute wsa = (WebMethodAttribute)objs;
if (wsa != null)
return "Session: " + wsa.EnableSession;
BTW, generally, it is not recommended that we use SessionState or other
stateful storage in Webservice since they're platform dependent.
Hope this helps.
Microsoft Online Community Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
|Thread Tools||Search this Thread|