问题
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?
回答1:
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;
}
回答2:
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.
回答3:
Here is an article on WS-ReliableMessaging, which has session support, and is supported on both java and .net development.
来源:https://stackoverflow.com/questions/3458604/session-management-in-web-services