Webservice and session

M

Morten V. Pedersen

Hello

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.

/Morten
 
S

Steven Cheng[MSFT]

Hi Morten,

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

===============
MethodInfo mi = this.GetType().GetMethod("HelloWorld",
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.Public);


object[] objs = mi.GetCustomAttributes(typeof(WebMethodAttribute),
true);


if (objs != null && objs.Length >0)
{
WebMethodAttribute wsa = (WebMethodAttribute)objs[0];

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.



Regards,

Steven Cheng
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
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top