Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session State and Webservices

Status
Not open for further replies.

RicksAtWork

Programmer
Nov 1, 2005
120
GB
In my global asax I have:

protected void Global_AcquireRequestState(Object sender, EventArgs e)
{

// set the security principal to our BusinessPrincipal
if(Session["CSLA-Principal"] != null)
{
Thread.CurrentPrincipal = (IPrincipal)Session["CSLA-Principal"];
HttpContext.Current.User = Thread.CurrentPrincipal;
}
}


If I navigate to a webservice, I get the error:

Session state is not available in this context.

I need the session code in my global.asax file for the rest of my site, but it seems to be causing issues with webservices

What am I doing wrong?
 
A web service is not the same as a web page, therefore does not have session state. You will need to pass any values you want to the webservice.

Jim
 
Okay, but since Global_AcquireRequestState will be called when I call the Web Service, this error will always occur.

Is there anyway of getting round this, other than moving the session related code out the method AcquireRequestState????

Ideally I would like to keep the code here since it is needed for page requests.
 
I don't know of any way. But then again, I have not used Web Services much. Maybe someone else can give you some tips on what you can do.
 
A web service is not the same as a web page, therefore does not have session state

thats not entirely true: you can have user sessions, just add the enablesession attribute to the web method, like this:

[WebMethod(EnableSession=true)]
public string KillerMethod()
{...}

------------------------
 
See I told you someone would come through.. This is great to know... esdee

Jim
 
My error occurs before i specify a method - rather the problem occurs when i call the .asmx file without a reference to the method I want to execute.

Can you apply a similar tag to the whole webservice?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top