views:

298

answers:

2

I'm working on an application that makes a lot of HTTP "Web Services" requests, some of which can be rather large XML files. Right now the HTTP request is made on a second thread, so the GUI/Form is not locked up. But it is still unable to give the user feedback as to the progress of the request.

I've been using the HTTPWebRequest class for this work so far, and all my research points towards it not doing ASync progress reporting callbacks, until it is complete.

In the near future this app will have to upload large .jpg and .zip files, over 3G/GPRS. Without a progress bar or some type of feed back this will be very unpleasant to use.

Is there any other (possibly 3rd party) framework or Class I can use?

Please don't post code that works of Desktop .Net, and assume it works on CF, thanks.

A: 

Keep in mind that if the XML file is sent with the HTTP "Transfer-Encoding: chunked" header, HTTP does not tell you how big the file will be.

Robert Lewis
Even without knowing the final Content-Length.. it would be nice to give the user some feedback on the progress.
Alex
A: 

You can intercept the stream of bytes coming from the server with code like this:

HttpWebResponse response = request.GetResponse();

Stream responseStream = response.GetResponseStream();

Then you can wrap the response stream in your own class that reads from the HTTP stream and reports how many bytes have been received through an event. You will have to start your own separate thread for this to run on, and you will have to explicitly write the contents of the stream to a file. (I haven't tried this in CF, but these methods are documented as working for CF.)

Robert Lewis