Solved

Please wait page while webservice returns

Posted on 2003-11-19
4
253 Views
Last Modified: 2012-05-04
I invoke a webservice from a webapplication, this webservice contains an image which is realtime created, and takes quite a while.

I would like to ask you if you know a method how to show a "Please wait" page while the webservice returns.
In steps:
1. on the first page user clicks to a link which transfers the user to the page that would use the webservice.
2 I should display a page that says please wait the websevice is loading, or something like that
3 I show the page with the the result of the webservice

One more thing: I use a businesslayer object that invokes the webservices, I use the aspx files and their cs files just for representation.


0
Comment
Question by:baloghp
4 Comments
 
LVL 4

Expert Comment

by:wile_e_coyote
Comment Utility
You can invoke web services asynchronously using the web service proxy created by .NET.   Check out the following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service09032002.asp
0
 
LVL 1

Author Comment

by:baloghp
Comment Utility
Thanks,

But I found an easier way to do this, and I share it with you.

So If you wanna get a picture from websevice, but it takes long the following is a working solutin:
create a storage for the pic in an object that is stored sessiontime.

like:
class BusinessLayer
{
       public byte[] pic= null;
       public void íinvokeWebServiceThatRetrievesTheImage()
       {
                //call the webservice and store it in pic.
        }

}

Create an aspx(let's say preview.aspx) which will show the image; on it's onload do the following:

 BusinessLayer bl =(BusinessLayer)Session["BL"];
Page.BufferOutput = false;

if (bl.pic==null)
{
      Response.WriteFile("SomePicWhichIsSmall.jpg");
     bl.invokeWebServiceThatRetrievesTheImage();
}
else
{
     Response.WriteBinary(bl.pic);
}

All you have to do now is to set the source of the IMG tag in the containing page to preview.aspx; and write a little javascript that also sets it to preview.aspx?[some random number or the actual time]. make this javascript to run on Body onload. And you're ready.
Now a little explanation: first when the page loads to the client's browser you haven't even called the webservice. The bl.pic is null. So it will show "SomePicWhichIsSmall.jpg". But because the bufferOutput is turned off it won't wait untill the whole Page_OnLoad is fully finished, it will push the image to the browser immediately. Then, the webservice can take it's time to retrieve your image. When it's finished (and everithing is finished loading on that page) the browser will run your javascript which sets the source of your preview image to the same aspx file but with a so far unknown parameter. This parameter we only need to trick the browser's cache, so it will turn to the server again. This time since your webservice has already been called the bl.pic is not empty but containes the webservice's image. This time this image will be pushed to the browser.
And we got whar we wanted. First an image that says "please wait I'm working" only as long as the job really takes, and as soon as we got the real picture we show it.
One more thing before I finish. Don't ever forget to empty the pic buffer before calling the webservice again, or else it will give the previous webservice picture instead of the "please wait I'm working"  picture.

It took me a while to figure this out but this works fine. Hope someone else can also us the idea. It can be generalized for any kinda information that comes through webservices and takes a while untill you can show it to the user.
Bye now.
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
Comment Utility
PAQed, with points refunded (250)
ee_ai_construct - CS Mod
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
c# string 6 39
Get String split 5 31
Create XML 5 30
c# if statement weird reaction 3 29
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now