5,693,936 members and growing! (18,594 online)
Email Password   helpLost your password?
Web Development » Web Services » General     Intermediate License: The Code Project Open License (CPOL)

Web Form with progress bar of web service execution

By Forkossigan

Show developers how to manage state of long running web service and then use this state in ajax enabled web form
C# (C# 1.0, C# 2.0, C# 3.0, C#), .NET (.NET, .NET 2.0), Visual Studio, ADO.NET, Ajax, ASP.NET

Posted: 6 Aug 2008
Updated: 6 Aug 2008
Views: 3,470
Bookmarked: 10 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
2 votes for this Article.
Popularity: 1.10 Rating: 3.67 out of 5
1 vote, 50.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
1 vote, 50.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

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. Also this article show how to manage state of web service.

First look at web service code. To manage state of a web service we use 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;

Second. Web page have AJAX Timer which is disabled by default and start tick when user press start button and also have AJAX UpdatePanel to display progress bar, controls and GridView without full page postbacks.

Third. When user click "Start Process" buton we made async execution of a web service and pass values of IAsyncResult to Session object by following lines of code:

MyService.Test ts = new MyService.Test();

IAsyncResult my_ar;         // AsyncResult for async execution of service

my_ar = ts.BeginGo(UID, steps, values, null, null); // Start async execution of web service

Session["my_ar"] = my_ar;         // Remember AsyncResult in Session for later use
        

Fourth. When tick event occur we get IAsyncResult from Session and update controls with following lines of code:

IAsyncResult my_ar = (IAsyncResult)Session["my_ar"]; // Get IAsyncResult from Session

pw = ts.GetProcessValues(Session["WebServiceUID"].ToString()); // Get ProgressValues from web service

if (my_ar.IsCompleted) // Async execution of service done
 

Using the code

First of all - you need Microsoft AJAX installed on you 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 make this then Proxy class for you servce will be exists and you can use this proxy class in "Test" project.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Forkossigan



Location: Russian Federation Russian Federation

Other popular Web Services articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 6 Aug 2008
Editor:
Copyright 2008 by Forkossigan
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project