Solved

Please wait page while webservice returns

Posted on 2003-11-19
4
275 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

785 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