all groups > dotnet web services > february 2006 >
You're in the

dotnet web services

group:

download File From a WEB Service in Windows Form


download File From a WEB Service in Windows Form Tom
2/23/2006 5:31:48 PM
dotnet web services:
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

Re: download File From a WEB Service in Windows Form Pierre
2/24/2006 5:04:24 AM
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\\Pictures\\";


[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
Re: download File From a WEB Service in Windows Form Tom
2/24/2006 3:33:36 PM
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!


Re: download File From a WEB Service in Windows Form Pierre
2/27/2006 4:48:03 AM
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.
AddThis Social Bookmark Button