views:

82

answers:

3

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
@Achilles: how does Session work in a web-service? any sample code available?
brainless
`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
+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
@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
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
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
@ŁukaszW.pl: Thanks :-)small change is required in your answer as follows.[WebMethod(SessionEnabled = true)] - Wrong[WebMethod(EnableSession=true)] - Right
brainless
Haha.. It's just because I wrote it from my head ;)
ŁukaszW.pl
A: 

Here is an article on WS-ReliableMessaging, which has session support, and is supported on both java and .net development.

mdma