Hi all, I am trying to send an image with a content-type of multipart/form-data to a webservice but got a 500 Internal Server Error. The following is my Javascript function to send the image and receive a status message from the webservice.
xhr = new XMLHttpRequest();
xhr.open('post', 'http://localhost:26692/SavePicService.asmx?op=SaveImage', true);
//xhr.setRequestHeader('Content-Type', "multipart/form-Data");
xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded");
xhr.setRequestHeader('X-File-Name', file.fileName);
xhr.setRequestHeader('X-File-Size', file.fileSize);
xhr.setRequestHeader('X-File-type', file.fileType);
xhrObj.send(file);
var responseObject = xhr.responseText;
alert(responseObject); // ------- Test status of uploadThis is a simple webserivce to test if data is successfully being received and response is sent back by webservice.
namespace myNameSpace
{
/// <summary>
/// Summary description for SavePicService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class SavePicService : System.Web.Services.WebService
{
[WebMethod]
public string SaveImage()
{
return "Data Transfer Successful!";
}
}
}At first my content-type was set to "multipart/form-Data" in my javascript upload function but I got the 500 internal service error. After doing some digging online I came across an article that says that the content-type must be set to "application/x-www-form-urlencoded" or the 500 internal server error will be thrown. Needless to say, that still results in the same error. Please point out where I went wrong in my code, thanks in advance.