Click here to Skip to main content
Licence CPOL
First Posted 6 Aug 2008
Views 16,754
Downloads 276
Bookmarked 23 times

Web Form with Progress Bar of Web Service Execution

By Forkossigan | 6 Aug 2008
Show developers how to manage state of long running web service and then use this state in Ajax enabled web form
 
Part of The SQL Zone sponsored by
See Also
1 vote, 50.0%
1

2

3

4
1 vote, 50.0%
5
3.67/5 - 2 votes
μ 3.67, σa 4.95 [?]

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. This article also shows how to manage state of web service.

  1. 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;
  2. 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.

  3. 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;
  4. 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)  

Using the Code

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.

History

  • 6th August, 2008: Initial post

License

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

About the Author

Forkossigan



Russian Federation Russian Federation

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWeb object created every time that the timer is called? PinmemberLEM313:38 20 Jul '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 6 Aug 2008
Article Copyright 2008 by Forkossigan
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid