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?
+5
A:
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
2010-08-11 13:14:58
@Achilles: how does Session work in a web-service? any sample code available?
brainless
2010-08-11 13:17:07
`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.
ŁukaszW.pl
2010-08-11 13:20:38
+2
A:
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;
}
ŁukaszW.pl
2010-08-11 13:18:13
@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
2010-08-11 13:24:18
Session 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.
ŁukaszW.pl
2010-08-11 13:28:37
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
2010-08-11 13:37:45
@ŁukaszW.pl: Thanks :-)small change is required in your answer as follows.[WebMethod(SessionEnabled = true)] - Wrong[WebMethod(EnableSession=true)] - Right
brainless
2010-08-12 09:18:03