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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pierre - 27 Feb 2006 10:46 GMT
Hi all,

I am using a web service to transfert documents between my client and
the server (code underneath). The problem is that I don't get any error
but I don't transert anything either. One of my ex-colleague used it,
so I assumed it would work.

Web Service:
[WebService(Namespace = "http://webservices.harlington-straker.co.uk")]
[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("http://webservices.harlington-straker.co.uk");
           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("http://webservices.harlington-straker.co.uk");
           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("http://webservices.harlington-straker.co.uk");
           mger.SetException(e);
           SoapException se = new SoapException("Fault occured",
SoapException.ClientFaultCode, Context.Request.Url.AbsoluteUri,
mger.GetExceptionNode());
           throw se;
       }
       return documentcontents;
   }

Client:
   protected string _sFile;
   protected void Page_Load(object sender, EventArgs e)
   {
       Button2.Text = "Get";
       Button1.Text = "Save";
       _sFile =
"C:\\Inetpub\\wwwroot\\Hss.Com.WebServices\\Pictures\\jay2.jpg";
   }

   protected void Button2_Click(object sender, EventArgs e) {
       try  {
           MemoryStream objstreaminput = new MemoryStream();
           //FileStream objfilestream = new FileStream(sFile,
FileMode.Create, FileAccess.ReadWrite);
           FileStream objfilestream = new
FileStream(_sFile.Insert(_sFile.LastIndexOf("."), "2"),
FileMode.Create, FileAccess.ReadWrite);

           Manage_Document.Manage_Document myservice = new
Manage_Document.Manage_Document();
           int len = (int)myservice.GetDocumentLen(_sFile.Remove(0,
_sFile.LastIndexOf("\\") + 1));
           Byte[] mybytearray = new Byte[len];
           mybytearray = myservice.GetDocument(_sFile.Remove(0,
_sFile.LastIndexOf("\\") + 1));
           objfilestream.Write(mybytearray, 0, len);

           objfilestream.Close();
       }catch(SoapException error) {
           string test;
           string test2;
           test = error.Code.Name;
           test2 = error.Detail.OuterXml;
       } catch(Exception ext) {
           string pwet = ext.Message;
       }
   }

   protected void Button1_Click(object sender, EventArgs e) {
       try {
           FileStream objfilestream = new FileStream(_sFile,
FileMode.Open, FileAccess.Read);
           int len = (int)objfilestream.Length;
           Byte[] mybytearray = new Byte[len];
           objfilestream.Read(mybytearray, 0, len);
           Manage_Document.Manage_Document myservice = new
Manage_Document.Manage_Document();
           myservice.SaveDocument(mybytearray, _sFile.Remove(0,
_sFile.LastIndexOf("\\") + 1));
           objfilestream.Close();
       } catch { }
   }

Could it be that I don't have the rights to go on this directory?

Thank you for any help and ideas.
Pierre
Pierre - 27 Feb 2006 12:47 GMT
I have found what I needed:

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

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.