HighTechTalks DotNet Forums  

Webservice and session

ASP.net Web Services microsoft.public.dotnet.framework.aspnet.webservices


Discuss Webservice and session in the ASP.net Web Services forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Morten V. Pedersen
 
Posts: n/a

Default Webservice and session - 05-10-2006 , 03:20 AM






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



Reply With Quote
  #2  
Old   
AT
 
Posts: n/a

Default RE: Webservice and session - 05-10-2006 , 08:58 PM






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


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.