473,385 Members | 1,919 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,385 software developers and data experts.

download File From a WEB Service in Windows Form

Tom
I'm wiritng a dot.net windows forms appliction that needs to connect to a
webservice to download some files.
I need to show a progress bar during the download, bacause some file can be
very big.
How Can i Mkae this?
Can i use a stream?
There are some samples?

I'm thinking to use a byte array to get, for each call, a chunck of bytes,
but I think also that in this way i'll made a lot of HTTP calls...

Thank you
Feb 23 '06 #1
3 2718
Hi Tom,

I use a service like that:

<%@ WebService Language="C#" Class="Manage_Document" %>
using System.Configuration;
using System;
using System.Xml;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.IO;
using Hss.Com.WebServices.ExceptionsHandler;

[WebService(Namespace = "http://here.is.your.namespeace")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Manage_Document : System.Web.Services.WebService {
protected string _file_path =
"C:\\Inetpub\\wwwroot\\Hss.Com.WebServices\\Pictur es\\";
[WebMethod]
public bool SaveDocument(Byte[] docbinaryarray, string docname) {
try {
string strdocPath;
strdocPath = _file_path + docname;
FileStream objfilestream = new FileStream(strdocPath,
FileMode.Create, FileAccess.ReadWrite);
objfilestream.Write(docbinaryarray, 0,
docbinaryarray.Length);
objfilestream.Close();
} catch(Exception e) {
SoapExceptionManager mger = new
SoapExceptionManager(Namespaces.WebService);
mger.SetException(e);
SoapException se = new SoapException("Fault occured",
SoapException.ClientFaultCode, Context.Request.Url.AbsoluteUri,
mger.GetExceptionNode());
throw se;
}
return true;
}

[WebMethod]
public int GetDocumentLen(string DocumentName) {
string strdocPath;
strdocPath = _file_path + DocumentName;
int len;
try {
FileStream objfilestream = new FileStream(strdocPath,
FileMode.Open, FileAccess.Read);
len = (int)objfilestream.Length;
objfilestream.Close();
} catch(Exception e) {
SoapExceptionManager mger = new
SoapExceptionManager(Namespaces.WebService);
mger.SetException(e);
SoapException se = new SoapException("Fault occured",
SoapException.ClientFaultCode, Context.Request.Url.AbsoluteUri,
mger.GetExceptionNode());
throw se;
}
return len;
}

[WebMethod]
public Byte[] GetDocument(string DocumentName) {
string strdocPath;
strdocPath = _file_path + DocumentName;
Byte[] documentcontents;
try {
FileStream objfilestream = new FileStream(strdocPath,
FileMode.Open, FileAccess.Read);
int len = (int)objfilestream.Length;
documentcontents = new Byte[len];
objfilestream.Read(documentcontents, 0, len);
objfilestream.Close();
} catch(Exception e) {
SoapExceptionManager mger = new
SoapExceptionManager(Namespaces.WebService);
mger.SetException(e);
SoapException se = new SoapException("Fault occured",
SoapException.ClientFaultCode, Context.Request.Url.AbsoluteUri,
mger.GetExceptionNode());
throw se;
}
return documentcontents;
}
}

I found the base of this code somewhere online but there was no licence
on it, feel free to use and modify it at your will. The Soap Exceptions
Handler is home made, but I can give that as well if anybody needs it
;)

I hope this help.

Best regards,
Pierre

Feb 24 '06 #2
Tom
Using this code i am unable to show a progress bar because with the
getdocument method i get all the byte array..

If a file is large (es 20 MB) the time needed is too high!

Feb 24 '06 #3
I also had a problem with my code. Here is exactly what you want:

http://www.codeproject.com/soap/MTOMWebServices.asp

I hope it helps.

Feb 27 '06 #4

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

Similar topics

0
by: Jagdeesh | last post by:
Hai Colleagues, I am using Tomcat 4.1.24 and JDK 1.4.0_03 in my winXP machine. I've transferred a set of folders(containing jsp files) into tomcat's webapps directory(to /webapps/bob ,...
1
by: Navin | last post by:
hi, guys i am using the following code to force a file download dialog in asp Response.ContentType = "application/vnd.ms-excel" response.AddHeader "content-disposition","attachment; filename="...
2
by: Eric Caron | last post by:
Hi Here's my problem, I create a windows service with Config.xml file. All setup for my service is in this file. I create a windows application to manage these settings (Config.XML File). This...
4
by: Kevin Muenzler, WB5RUE | last post by:
How do I force a browser to download a file instead of displaying it? In other words I have a page with MP3 and WMA files on it and I would like for the visitor to download the file instead of...
2
by: Andy Johns | last post by:
I've seen plenty of examples of file uploads in ASP.NET when the only form element is the file input type, but I've not seen a practical example of a file upload routine running alongside other...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
2
by: Suman | last post by:
Happy Friday everyone!!! I am working on a windows service and a C# application and needed some help with certain functionality. Please read through my issue below. Thanks! I have a windows...
1
by: noah.blumenthal | last post by:
I wrote a windows service in c# (applause) and now I want to add the ability to edit its settings. Basically this service checks an email account at certain intervals and forwards the emails to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.