i have a web service which contains a method like the following
[WebMethod]
public string UploadFile(byte[] bytes, string file_name)
{
}
i want to invoke this web service method using HttpWebRequest so that i can stream the file without buffering in memory. How can do it... i tried to invoke it as follows
HttpWebRequest hw = HttpWebRequest.Create("http://localhost/xxx/xxx.asmx/Upload") as HttpWebRequest;
hw.ContentType = "application/x-www-form-urlencoded";
hw.AllowWriteStreamBuffering = false;
hw.Method = "POST";
hw.UnsafeAuthenticatedConnectionSharing = true;
hw.UserAgent = "test type";
hw.Credentials = CredentialCache.DefaultCredentials;
FileInfo fi = new FileInfo("C:/Documents and Settings/Administrator/Desktop/a.txt");
string bytes = "bytes=";
byte[] by = UTF8Encoding.UTF8.GetBytes(bytes);
byte[] fn = UTF8Encoding.UTF8.GetBytes("&file_name=a.txt");
hw.ContentLength = by.Length+fi.Length+fn.Length;
using (Stream postStream = hw.GetRequestStream())
{
FileStream br = new FileStream("C:/Documents and Settings/Administrator/Desktop/a.txt", FileMode.Open, FileAccess.Read);
postStream.Write(by, 0, by.Length);
byte[] buffer = new byte[1024];
int bytesRead = 0;
while (true)
{
bytesRead = br.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
postStream.Write(buffer, 0, bytesRead);
}
br.Close();
postStream.Write(fn, 0, fn.Length);
postStream.Write(ct, 0, ct.Length);
}
// HERE :
using (HttpWebResponse response = hw.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string sssdd = reader.ReadToEnd();
}
but it show a message "The remote server returned an error: (500) Internal Server Error." while executing **// HERE : ** marked line.
btw: i am using asp.net 2.0 and i am not allowed to use proxy class as my requirement is to stream the data for large file. Thanks in advance