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

download File From a WEB Service

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\\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("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\\Pictur es\\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

Feb 27 '06 #1
1 1355
I have found what I needed:

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

Feb 27 '06 #2

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

Similar topics

6
by: Samir | last post by:
Hello, I have a website that is hosted by another company. Is there some kind of php script to limit downloading to a certain amount size? And is there kind thing I can do to the .htaccess...
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="...
0
by: Martin Raychev | last post by:
Hi everybody, I have a need for a web app that will allow a flash client to download files at a specified speed. I am using Flash for an application of mine which downloads JPG slides to...
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...
0
by: CodeMotion | last post by:
I have access to an internet directory and files will be placed in this directory periodically. I am writing a service to poll that directory and download the files for processing. I have figured...
9
by: Mark Olbert | last post by:
I have an application whose installer can be downloaded from the Internet as an MSI file (by clicking on a link). The content-type parameter is set to application/octet-stream. Under Firefox,...
6
by: Marc Ris | last post by:
Hi, Following problem, and I can't find any solution for that: I have an aspx page, which will (finally) generate an XLS-File which must (can) be downloaded from the user. After that, the...
6
by: Jatin | last post by:
Hey Guys I have a web application that allows users to download files. But the files are not hosted on the webserver. The files are stored on external servers and are referenced by a URL/URI....
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.