Introduction:
In this article,we are going to discuss about how to create sessions in web services.
Main:
Normally asp.net web services provided the following two types of state management,
1.Client state, in which data about a particular client request is stored and used to affect the processing of future requests from that client.
2.Application state, which is not client specific. Data from any request (regardless of the client) is stored and used to affect the processing of any future request.
EnableSession=true property in web method will enable the client session.
Syntax is,
[WebMethod(EnableSession=true)]
Check this below simple examble,Just managed the old dataset using session,
[WebMethod(EnableSession=true)]
public DataSet RetrieveDataSet() {
DataSet ResultSet = (DataSet)Session["DataSource"];
if (ResultSet == null) {
ResultSet = new DataSet();
Session["DataSource"] = ResultSet;
}
return ResultSet;
}
Conclusion:
Hope this helps,
Happy Coding.