I wrote a simple webservice for uploading a file.
<%@ WebService Language="C#" class="AppWebService" %>
using System;
using System.Web.Services;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.IO;
[WebService(Namespace="http://myip/services")]
public class AppWebService : WebService
{
[WebMethod]
public string UploadFile(byte[] f, string fileName)
{
// the byte array argument contains the content of the file
// the string argument contains the name and extension
// of the file passed in the byte array
try
{
// instance a memory stream and pass the
// byte array to its constructor
MemoryStream ms = new MemoryStream(f);
// instance a filestream pointing to the
// storage folder, use the original file name
// to name the resulting file
FileStream fs = new FileStream
(System.Web.Hosting.HostingEnvironment.MapPath("/TransientStorage/") +
fileName, FileMode.Create);
// write the memory stream containing the original
// file as a byte array to the filestream
ms.WriteTo(fs);
// clean up
ms.Close();
fs.Close();
fs.Dispose();
// return OK if we made it this far
return "OK";
}
catch (Exception ex)
{
// return the error message if the operation fails
return ex.Message.ToString();
}
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
Now I am trying to test the functionality but am having trouble interacting with the webservice via C#. I've searched around tried using HTTPWebrequest (multipart/form-data)
that I found in this post but didn't have much success and am not sure that this is the right approach.
How can I test the webservice that I wrote to see if I can successfully upload a file?