is it possible to manage sessions in web-services? if yes, how to manage session in it? is it similar to sessions we maintain in JSP or PHP? where does the info about the session will be stored, Client or Server?
Asked
Active
Viewed 1,832 times
4
-
I'm pretty sure...you need to rethink this approach. If you are familiar with web services in .net you would be aware that you "never, ever" use `Session` in them. – Achilles Aug 11 '10 at 13:36
3 Answers
5
It's possible to use the Session
object in .NET inside of a webservice...however I'd say it is bad practice. Typically speaking a webservice isn't passed data this way and the data in the service doesn't persist between calls.

Achilles
- 11,165
- 9
- 62
- 113
-
1
-
1`Session` in webservices works just like on any aspx pages. You can put objects into session table and retrieve it from there. Also it's possible for you to use session-based mechanisms like `FormsAuthentication` etc. – Łukasz W. Aug 11 '10 at 13:20
3
Is it java or .net question?
In .net you can easily use session state on webservice hosting server by setting EnableSession
parameter in WebMethod
attribute, for example:
[WebMethod(EnableSession = true)]
public bool Login(string login, string password)
{
// you can use session here so for example log in user
if(login = "administrator" && password = "secret")
Session["authorizedUser"] = login;
}

Łukasz W.
- 9,538
- 5
- 38
- 63
-
@LukaszW.pl: is it similar to sessions we maintain in JSP or PHP? where does the info about the session will be stored, Client or Server? – brainless Aug 11 '10 at 13:24
-
2Session is always server side thing... It's similar to session in PHP (I don't know JSP)... Generaly it's client-unique table of objects that is stored on the server which you can easily access from your C# web application that hosts the webservice. – Łukasz W. Aug 11 '10 at 13:28
-
Since a web service is a normal web app, just one that handles requests and responses in forms other than HTML, the same session management mechanisms are used. – matt b Aug 11 '10 at 13:37
-
Thanks :-) small change is required in your answer as follows. [WebMethod(SessionEnabled = true)] - Wrong [WebMethod(EnableSession=true)] - Right – brainless Aug 12 '10 at 09:18
-