473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Web Service Sample for Downloading Files?

Ken
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.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #1
8 14106
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.
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 = new System.IO.FileStream(fileName, System.IO.FileMode.Open);
byte[] barr = 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 = new System.IO.FileStream(fileName, System.IO.FileMode.Open);
int len = fs.Length;
//If you are requesting bytes beyond file length, abort.
if (offset > len) return new byte[0];
//else get the file
if (len < offset + length)
{
len = len - offset; //if you are at the end of file, you need less bytes.
}
else
{
len = length;
}
byte[] barr = 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.

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.

Enjoy!

Regards,

Sigmund Jakhel
MCSD.NET

"Ken" <krcourville_atsign_msn_period_com> wrote in message news:u%****************@TK2MSFTNGP15.phx.gbl...
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.

*** Sent via Developersdex http://www.developersdex.com ***

Nov 23 '05 #2
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.
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 = new System.IO.FileStream(fileName, System.IO.FileMode.Open);
byte[] barr = 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 = new System.IO.FileStream(fileName, System.IO.FileMode.Open);
int len = fs.Length;
//If you are requesting bytes beyond file length, abort.
if (offset > len) return new byte[0];
//else get the file
if (len < offset + length)
{
len = len - offset; //if you are at the end of file, you need less bytes.
}
else
{
len = length;
}
byte[] barr = 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.

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.

Enjoy!

Regards,

Sigmund Jakhel
MCSD.NET

"Ken" <krcourville_atsign_msn_period_com> wrote in message news:u%****************@TK2MSFTNGP15.phx.gbl...
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.

*** Sent via Developersdex http://www.developersdex.com ***

Nov 23 '05 #3
Ken <krcourville_atsign_msn_period_com> wrote in news:u#KlgmiYFHA.3356
@TK2MSFTNGP15.phx.gbl:
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.


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"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #4
Ken <krcourville_atsign_msn_period_com> wrote in news:u#KlgmiYFHA.3356
@TK2MSFTNGP15.phx.gbl:
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.


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"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #5
Ken
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.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #6
Ken
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.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #7
Ken <krcourville_atsign_msn_period_com> wrote in news:OwNUOWeZFHA.3908
@TK2MSFTNGP15.phx.gbl:
The byte array makes sense. If http is better, how so? Can you point
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.
me to sample code?
No, but its very easy.
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.


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"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #8
Ken <krcourville_atsign_msn_period_com> wrote in news:OwNUOWeZFHA.3908
@TK2MSFTNGP15.phx.gbl:
The byte array makes sense. If http is better, how so? Can you point
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.
me to sample code?
No, but its very easy.
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.


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"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: PatrickSA | last post by:
Hi, Am new to web services, so apologies for the basic nature of the question - and apologies in advance if this is the wrong newsgroup. We're building a new web service and I'm looking around...
4
by: Joe | last post by:
I'm hosting my web service on a Windows 2003 box which is remotely located. When trying to add a web reference to a C# project I get an error message 'There was an error downloading...
0
by: Ken | last post by:
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. ...
2
by: heddy | last post by:
Howdy folks. I am trying to build a web service using the following configuration: I have Windows 2003 Server running in VMware. I have IIS set up on it. I installed the .NET 2.0 package on...
4
by: carson | last post by:
I have written two windows services: - service A does some crunching of local data files and uploads them to a central processing computer via http. - service B monitors a manifest file on a...
1
by: apondu | last post by:
Hi, I am new to web services and i am facing a problem. I am interested in downloading some file from internet and use it for furthur processing For eg. i have a file at a the following URL and...
1
by: apondu | last post by:
Hi, I am new to web services and i am facing a problem. I am interested in downloading some file from internet and use it for furthur processing For eg. i have a file at a the following URL and...
13
by: dancer | last post by:
I have made a new post because when I try to respond to another, I get the error, "Article Rejected -- Ill-formed message id" This is in response to the advice of Juan Libre to install Net...
4
by: TampaWebDevelopment | last post by:
I have just finished a Windows Service that I have been working on for quite some time that works pretty well and is fairly useful. To this point, editing configuration items of the service...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.