Howdy, Stranger!

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


Internal Service Error 500 when posting FormData to web service

super_drysuper_dry Posts: 1
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 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!");
}"POST", 'http://localhost:59541/WebService.asmx/Upload', true);

My C# Web Service:

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

namespace MouseEditor
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
public String Upload(byte[] bytes)
return "This is a test";
Sign In or Register to comment.