Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / February 2006

Tip: Looking for answers? Try searching our database.

download File From a WEB Service in Windows Form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom - 23 Feb 2006 16:31 GMT
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
Pierre - 24 Feb 2006 13:04 GMT
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
Tom - 24 Feb 2006 14:33 GMT
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!
Pierre - 27 Feb 2006 12:48 GMT
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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.