A Session is one of the server-side state management techniques that stores the user specific data across the user request.
- By default a session is not enabled in a web service; we need to enable it using the following procedure.
- The default time out of the session is 20, the same as any web application.
- A Session is defined in the Web.config file, similar to any web application.
- The default session mode is Inproc in which session data is saved to the IIS worker process.
Since I have already said that by default a session is not enabled in a web service, we need to enable it with the following procedure. So let us discus the procedure.
- EnableSession property
- To enable the session in a web service it must use the EnableSession Property of the WebMethod attribute.
- It must set EnableSession to true as shown in the preceding example.
- Without setting the EnableSession property to true, the session will not work otherwise the unhandled exception occurs.
- It must be need to inherit the Web Service class from system.Web.Services class as shown in the preceding class to support the session, otherwise it will not support the session.
- "Start" - "All Programs" - "Microsoft Visual Studio 2010".
- "File" - "New Project" - "C#" - "ASP.NET Empty Web Application" (to avoid adding a master page).
- Provide the web site a name such as "SessionInWebService" or another as you wish and specify the location.
- Then right-click on Solution Explorer - "Add New Item" then you will see the web service templates.
- Right-click on the existing Solution Explorer.
- Then choose Add New Item.
- Select .aspx Page from the template list, define the name and click on OK
- Click here SessionInWebService.zip to Download the Zip file for the full source code of the application.
I hope this article is useful for all readers, if you have any suggestion then please contact me including beginners also.