Solved

Please wait page while webservice returns

Posted on 2003-11-19
4
281 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
ID: 9779367
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
ID: 9805741
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
ID: 11747199
PAQed, with points refunded (250)
ee_ai_construct - CS Mod
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 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