You don't need to use any fancy "web service" technology to upload data from a client application to a server. You can create a simple ASP.NET Web handler and save the input file from the request body:
public class FileUploader : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string fileName = context.Request.QueryString["FileName"];
byte[] fileData = context.Request.BinaryRead(context.Request.ContentLength);
string path = ...; // decide where you want to save the file
File.WriteAllBytes(path, fileData);
}
public bool IsReusable
{
get { return false; }
}
}
From the client app, you'd use WebClient.UploadFile
method:
using (var client = new WebClient()) {
client.QueryString["FileName"] = fileName;
client.UploadData(url, inputFileData);
}
This approach eliminates the overhead of protocols like SOAP and posts the file directly in the HTTP request body.
Mehrdad Afshari
2010-06-07 10:57:41