473,666 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14166
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(str ing 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.FileS tream fs = new System.IO.FileS tream(fileName, System.IO.FileM ode.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(str ing 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.FileS tream fs = new System.IO.FileS tream(fileName, System.IO.FileM ode.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_at sign_msn_period _com> wrote in message news:u%******** ********@TK2MSF TNGP15.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(str ing 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.FileS tream fs = new System.IO.FileS tream(fileName, System.IO.FileM ode.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(str ing 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.FileS tream fs = new System.IO.FileS tream(fileName, System.IO.FileM ode.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_at sign_msn_period _com> wrote in message news:u%******** ********@TK2MSF TNGP15.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_at sign_msn_period _com> wrote in news:u#KlgmiYFH A.3356
@TK2MSFTNGP15.p hx.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/
"Programmin g is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #4
Ken <krcourville_at sign_msn_period _com> wrote in news:u#KlgmiYFH A.3356
@TK2MSFTNGP15.p hx.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/
"Programmin g 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_at sign_msn_period _com> wrote in news:OwNUOWeZFH A.3908
@TK2MSFTNGP15.p hx.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/
"Programmin g is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #8
Ken <krcourville_at sign_msn_period _com> wrote in news:OwNUOWeZFH A.3908
@TK2MSFTNGP15.p hx.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/
"Programmin g 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
528
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 for documentation on a number of issues, including versioning of web service interfaces... I've spent the last few hours looking through books, Google, MSDN and surprisingly I have found little or nothing that explains/shows how to practically...
4
2928
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 'http://mydomain.com:port/webservice.asmx' The operation has timed-out (I've tried with and without using a separate port for the service) The weird thing is the page does show up on the left side of the screen listing the available methods but the Add...
0
952
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. *** Sent via Developersdex http://www.developersdex.com ***
2
2173
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 the server as well. The VMWare server is called W2K3. I created 2 web sites on the server. One called ResetPool, the other called TestReset. The ResetPool site is the target of a little web service that will force an app pool to recycle. The...
4
21717
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 webserver to see if service A needs to be updated. What service B does if it sees their is an update for service A is to download a new copy of the service A executable, stop service A, replace the executable with the new copy, and start service B...
1
1682
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 i want to download that file in the web service which i am coding and use it for furthur. In normal window application i can achieve this by the following code
1
1520
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 i want to download that file in the web service which i am coding and use it for furthur. In normal window application i can achieve this by the following code
13
6643
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 Framework Service Pack 1 in order to use ASP.net 1.1 and the net Framework 1.1 ------------------------------------------------------------------------------------------------ I found the following file, "svcpack.log" at C:\WINNT. It contains many...
4
2934
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 requires manually editing the config.xml file. This is completely fine for me. But, I just decided that I want to build a nice little GUI for the service, give it a tray icon, and release it for all to use. I have developed plenty of desktop...
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7378
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.