Part 3 Using ASP NET Session State in a Web Service HD
Link for code samples used in the demo http://csharp-video-tutorials.blogspot.com/2013/11/part-3-using-aspnet-session-state-in.html Link for all dot net and sql server video tutorial playlists http://www.youtube.com/user/kudvenkat/playlists In this video, we will discuss using asp.net session variables in a web service. This is continuation to Part 2. Please watch Part 2 from the ASP.NET tutorial before proceeding. To use asp.net Session object in a web service, the web service class must inherit from System.Web.Services.WebService class and EnableSession property of WebMethod attribute must be set to true. Let us now use Session object with the Calculator Service that we have built in Part 2. We want to display all the calculations that a user has performed as shown below. Here are the steps to achieve this. Step 1: Copy and paste the following code in CalculatorWebServices.asmx file using System.Web.Services; using System.Collections.Generic; namespace WebServicesDemo { [WebService(Namespace = "http://pragimtech.com/webservices")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] public class CalculatorWebServices : System.Web.Services.WebService { [WebMethod(EnableSession = true)] public int Add(int firstNumber, int secondNumber) { List[string] calculations; if (Session["CALCULATIONS"] == null) { calculations = new List[string](); } else { calculations = (List[string])Session["CALCULATIONS"]; } string strTransaction = firstNumber.ToString() + " + " + secondNumber.ToString() + " = " +