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