Web services have not any mechanism by which can maintain state. But web services can access asp.net objects like Session, Application and so on if they are inherit from web services bass class.
In this article, I would demonstrate how Session and Application Object can maintain by Web Services. I have created a web form called Session-Application.aspx, which only includes a buttons named. If you click on a button, an event is triggered, and the Web service calls:
Session objects store information between HTTP request for a particular user.
<form id="form1" runat="server">
<asp:Button ID="BtSession" runat="server" Text="Session"
protected void BtSession_Click(object sender, EventArgs e)
Session["Session"] = "aspxtutorial.com";
MyWebServices WS = new MyWebServices();
Object T = WS.getSessionValue();
Protected Sub BtSession_Click(sender As Object, e As EventArgs)
Session("Session") = "aspxtutorial.com"
Dim WS As New MyWebServices()
Dim T As [Object] = WS.getSessionValue()
Here is a preview of the Object that will be returned.
Application object can be used in situation where we want data to be shared across users globally.
Session-Application.rar (2.36 kb)
See Live Demo