all groups > dotnet web services > may 2005 >
You're in the

dotnet web services

group:

Web Service Sample for Downloading Files?


Web Service Sample for Downloading Files? Ken
5/26/2005 12:32:16 PM
dotnet web services: Can anyone point me to some info, which gives me an idea of how to go
about making an ASP.NET web service to download files

I plan to access the web service from a C# Windows App.

Thanks.

Re: Web Service Sample for Downloading Files? Chad Z. Hower aka Kudzu
5/31/2005 12:00:00 AM
Ken <krcourville_atsign_msn_period_com> wrote in news:u#KlgmiYFHA.3356
@TK2MSFTNGP15.phx.gbl:
[quoted text, click to view]

If you are only downloading files, HTTP is a better choice.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Re: Web Service Sample for Downloading Files? Ken
5/31/2005 6:35:04 AM
Thanks for the responses.

I was researching this a bit more and found mention of using DIME over
http.

The byte array makes sense. If http is better, how so? Can you point
me to sample code?

My basic goal here is to make an application update service where the
remote client will query the web service for new files then download the
files it needs.



Re: Web Service Sample for Downloading Files? Ziga Jakhel
5/31/2005 11:06:07 AM
Well... if you are transferring files, you are basically transfering =
bytes. So a simple way would be to simply return a byte array, which you =
can then save on the client.=20


Example:

[WebMethod]
public byte[] GimmeMyFile(string fileName)
{
//Do whatever magic you need to do to get the file and transfer it into =
a bytestream.
//A simple example is this:
System.IO.FileStream fs =3D new System.IO.FileStream(fileName, =
System.IO.FileMode.Open);
byte[] barr =3D new byte[fs.Length];
fs.Read(barr, 0, fs.Length);
return barr;
}


If you have extremely large files or so many requests you would clog up =
your ws server memory, you can implement your own mechanism for chunking =
the file and transferring inidividual chunks. An example:

[WebMethod]
public byte[] GimmeMyFile(string fileName, int offset, int length)
{
//Do whatever magic you need to do to get the file and transfer it into =
a bytestream.
//A simple example is this:
System.IO.FileStream fs =3D new System.IO.FileStream(fileName, =
System.IO.FileMode.Open);
int len =3D fs.Length;
//If you are requesting bytes beyond file length, abort.=20
if (offset > len) return new byte[0];
//else get the file
if (len < offset + length)
{
len =3D len - offset; //if you are at the end of file, you need less =
bytes.
}
else
{
len =3D length;
}
byte[] barr =3D new byte[len];
fs.Read(barr, offset, len);
return barr;
}

This way you would simply keep calling the method with increasing =
offsett (by the chunk size) until you get back a chunk that's shorter =
then the chunk size you requested. Then you know you've reached the end =
of the file.=20

If you have larger files or narrow communication channels you may =
consider compressing the file before transfer (and then uncompressing it =
again on the client); for this Google up SharpZipLib. Works decently =
fast.=20

Enjoy!

Regards,

Sigmund Jakhel
MCSD.NET



[quoted text, click to view]
Re: Web Service Sample for Downloading Files? Chad Z. Hower aka Kudzu
6/3/2005 12:23:35 PM
Ken <krcourville_atsign_msn_period_com> wrote in news:OwNUOWeZFHA.3908
@TK2MSFTNGP15.phx.gbl:
[quoted text, click to view]

Because if you arent requiring all the extras SOAP provides, its always best
to use the simplest solution that meets your needs, and HTTP can easily
download a file.

[quoted text, click to view]

No, but its very easy.

[quoted text, click to view]

What kind of query will you be submitting?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

AddThis Social Bookmark Button