Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Internal Service Error 500 when posting FormData to web service

super_drysuper_dry Posts: 1Member
Hello all,

I am attempting to upload a file from a HTML page to my C# Web service using XMLHTTPRequest to post FormData to my Web Service that is expecting a byte array.

My other XMLHTTPRequest posts from my HTML Javascript work, however there is something I don't understand about posting files to C# Web Service using FormData.

My javascript XMLHTTPRequest reports state change to 0 and then [b]Internal Service Error 500[/b].

I've been trying for days and I ask out of desperation. Can anyone help?

Here are the important snippets. I'll add error trapping and different browser support once I can get the basics to work:

My HTML:

[code]
[/code]

My Javascript:

[code]function uploadFile() {

var file = document.getElementById('htmlinputfile').files[0]; // Get the single file from the html input field.
var formData = new FormData();
formData.append('file', file); // Append the file to the form data.
var request = new XMLHttpRequest(); // I am only using firefox, so no need to worry about ie.

request.onreadystatechange = function () {
alert("status:" + request.status + " " + request.statusText); // Displays 0 and then the 500 Internal Service Error.
if (request.readyState == 4 && request.status == 200) {
alert("Upload successful!");
}
}

request.open("POST", 'http://localhost:59541/WebService.asmx/Upload', true);
request.send(formData);[/code]

My C# Web Service:

[code]using System;
using System.Web.Services;
using System.IO;

namespace MouseEditor
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public String Upload(byte[] bytes)
{
return "This is a test";
}
}
}[/code]
Sign In or Register to comment.