views:

2021

answers:

5

I just wrote my first web service so lets make the assumption that my web service knowlege is non existant. I want to try to call a dbClass function from the web service. However I need some params that are in the session. Is there any way I can get these call these session variables from the webservice??

A: 

Maybe this will work HttpContext.Current.Session["Name] Or else you might have to take in some parameters or store them in a Database

Yitzchok
+4  A: 

If you are using ASP.NET web services and you want to have a session environment maintained for you, you need to embellish your web service method with an attribute that indicates you require a session.

[WebMethod(EnableSession = true)]
public void MyWebService()
{
    Foo foo;
    Session["MyObjectName"] = new Foo();
    foo = Session["MyObjectName"] as Foo;
}

Once you have done this, you may access session objects similar to aspx.

Metro.

Metro
+2  A: 

In general web services should not rely on session data. Think of them as ordinary methods: parameters go in and an answer comes out.

marc
A: 

Your question is a little vague, but I'll try my best to answer.

I'm assuming that your session variables exist on the server that is making the webservice call, and not on the server that hosts the webservice. In that case, you will need to pass the necessary values as parameters of your web service methods.

Kyle Trauberman
+1  A: 

You should avoid increasing the complexity of the service layer adding session variables. As someone previously pointed out, think of the web services as isolated methods that take all what is needed to perform the task from their argument list.

Pablo Marambio