using System; using System.Collections.Generic; using System.Web; using System.Web.Services; namespace Session_Test_Service { /// <summary> /// Summary description for Test_Session_Service /// </summary> [WebService(Namespace = "http://tempuri.org/service")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class Test_Session_Service : System.Web.Services.WebService { [WebMethod(EnableSession = true)] public int Calculate(int FirstNumber, int SecondNumber) { List<string> calculations; if (Session["CALCULATIONS"] == null) { calculations = new List<string>; } else { calculations = (List<string>)Session["CALCULATIONS"]; } string strRecentCalcuulation = FirstNumber.ToString()+ "+" +SecondNumber.ToString()+ " = " + (FirstNumber+SecondNumber).ToString(); calculations.Add(strRecentCalcuulation); return FirstNumber+SecondNumber; } [WebMethod(EnableSession = true)] public List<string> GetCalculation() { if (Session["CALCULATIONS"] == null) { List<string> calculations = new List<string>; calculations.Add("You have not performed any calculations"); return calculations; } else { return (List<string>)Session["CALCULATIONS"]; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)