Part 3 Using ASP NET Session State in a Web Service - YouTube

Link for code samples used in the demofor all dot net and sql server video tutorial playliststhis 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 fileusing System.Web.Services;using System.Collections.Generic;namespace WebServicesDemo{ [WebService(Namespace = "[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() + " = " + (firstNumber + secondNumber).ToString(); calculations.Add(strTransaction); Session["CALCULATIONS"] = calculations; return firstNumber + secondNumber; } [WebMethod(EnableSession = true)] public List[string] GetCalculations() { 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"]; } } }}Step 2: The next step is to update the proxy class in the client application, that is in the CalculatorWebApplication. To achieve this, right click on CalculatorService in Service References folder and select Update Service Reference option.Step 3: Copy and paste the HTML from by blog, as youtube doesnot allow HTML to be pasted in the description.Step 4: Copy and paste the following code in WebForm1.aspx.csusing System;namespace CalculatorWebApplication{ public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnAdd_Click(object sender, EventArgs e) { CalculatorService.CalculatorWebServicesSoapClient client = new CalculatorService.CalculatorWebServicesSoapClient(); int result = client.Add(Convert.ToInt32(txtFirstNumber.Text), Convert.ToInt32(txtSecondNumber.Text)); lblResult.Text = result.ToString(); gvCalculations.DataSource = client.GetCalculations(); gvCalculations.DataBind(); gvCalculations.HeaderRow.Cells[0].Text = "Recent Calculations"; } }}Step 5: In web.config file of CalculatorWebApplication, set allowCookies attribute to true. When allowCookies attribute is set to true, the client application accepts the cookie returned from the ASMX web service, and copies it into all future requests that are made to the web service. This ensures that the same session is maintained between the client and the web service.

sash e

God bless you I hope you find your sister


Have you found the bioshock easter egg?

hon da

I thougt the even worse is a raping thing worse than cheating

Stampeed- Mobile legends

The signature dunk is fake

Adam Long

Finished the game for like 2 weeks now

Roman Tatalovich

His is very nooby

82 GLX

Who still remembers dbz sagas

Tecnocrat Varakanava

Front Flip Flipper was awesome

MLG Zueira

Slerdeman Run!!

Jack Thomas

Sub to me

ralph de wael

Rolling down the hill haha!!

AbeCartoon LicolnGo!

That was my childhood...but almost kicked out..

Adam Fielding

Boston Red Sox

Elizabeth Morse

My cat died from kidney failure


Kylie White

I think you should do Alex morgan

Eugenio Sanchez

Sorry is


If I Was Her When The Mom Dragged Her Into The Car I Would Kick And Bite The Mom Until She Let Go

shadow fox

Ooooo do vacation stereotypes

MrSnipes 257

Teens react to Fnaf vr

Mandie McMurdie

the worlds most longest slingshot

tapani heinonen


Lame Llama


Brook Bridwell

I own one of those hulks

Shots Fired232

You guys should do a showing of your trophy's


Copyright 2006-2007 © Welding Co. All rights reserved.   |