![]() |
Web Development »
Web Services »
General
Intermediate
License: The Code Project Open License (CPOL)
Web Form with Progress Bar of Web Service ExecutionBy ForkossiganShow developers how to manage state of long running web service and then use this state in Ajax enabled web form |
C#.NET 2.0, ASP.NET, Visual Studio, ADO.NET, Ajax
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
The purpose of this article is to show how to get progress notifications of current web service progress. This will be achieved by using AJAX enabled web page, async call to web service and some easy CSS trick to display progress bar. This article also shows how to manage state of web service.
Look at the web service code. To manage state of a web service, we use a class named ProgressValues and Cache object. Values are stored in Cache with unique ID.
public class ProgressValues
{
public bool AbortPressed = false;
public int step = 0;
public int value = 0;
}
ProgressValues pw = new ProgressValues();
Context.Cache[UID] = pw;
Web page has an AJAX Timer which is disabled by default and starts tick when user presses the start button and also has AJAX UpdatePanel to display progress bar, controls and GridView without full page postbacks.
When user clicks "Start Process" button we make async execution of a web service and pass values of IAsyncResult to Session object by the following lines of code:
MyService.Test ts = new MyService.Test();
// AsyncResult for async execution of service
IAsyncResult my_ar;
// Start async execution of web service
my_ar = ts.BeginGo(UID, steps, values, null, null);
// Remember AsyncResult in Session for later use
Session["my_ar"] = my_ar;
When tick event occurs, we get IAsyncResult from Session and update controls with the following lines of code:
// Get IAsyncResult from Session
IAsyncResult my_ar = (IAsyncResult)Session["my_ar"];
// Get ProgressValues from web service
pw = ts.GetProcessValues(Session["WebServiceUID"].ToString());
// Async execution of service done
if (my_ar.IsCompleted)
First of all, you need Microsoft AJAX installed on your web server. Second, you need to compile/deploy/start TestService project into your web server, then add Web References to "Test project" with name MyService. If you do this, then Proxy class for your service will exist and you can use this proxy class in Test project.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Aug 2008 Editor: Deeksha Shenoy |
Copyright 2008 by Forkossigan Everything else Copyright © CodeProject, 1999-2009 Web09 | Advertise on the Code Project |