1

I have a problem submitting a complex JSON object to a .NET web service.

The Ajax JavaScript code:

$.ajax({
    type: "POST",
    url: WEBSERVICE_ADMINISTRATIO_URL + "RecieveData",

    data: JSON.stringify({data: _data}), // _data is the Javascipt object {}
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
        alert(data);
    },
    failure: function (errMsg) {
        alert(errMsg);
    },
    error: function (jqXHR, textStatus, errorThrow) {
        alert(textStatus);
    }
});

The .NET webservice

 [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string RecieveData(string data)
    {

        return "";
    }

I get an Internal Server Error 500 when trying to submit the data to the webservice from the client.

I have other webservice function that just return data and they work fine. I gave both GET and POST permission in the web.config.

Here's the detailed error:

"{"Message":"No parameterless constructor defined for type of 
 \u0027System.String\u0027.","StackTrace":"   at 
system.Web.Script.Serialization.ObjectConverter.ConvertDictionaryToObject(IDictionary`2 dictionary, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)\r\n   at 
System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)\r\n   at 
System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)\r\n   at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer serializer)\r\n   at System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary`2 rawParams)\r\n   at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\r\n   at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n   at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.MissingMethodException"}"

Thanks.

10
  • ...and what have you tried to debug this? Have you turned on some verbose error messages? Perhaps added a breakpoint and stepped into the method? ... "Internal Server Error" is just the default 500 response code. That means something went wrong - you're going to have to help us out by telling us what that is. Commented Aug 10, 2014 at 12:09
  • I get the error in the console in Chrome and the code returns to the "error" function of the $.ajax call. Is happens at the $.ajax call line where I call to the webservice (the exact Javascipt code I've shown above). The webservice code is as simple as possible. I therefore assume that it's an issue with how the data is sent to the webservice. Commented Aug 10, 2014 at 12:13
  • Put a breakpoint in that javascript error function and inspect the rest of the variables. If they give you only the generic 500 - Internal Server Error response then you need to enable some more verbose error messages on the .NET side. Perhaps forcefully turn <customErrors mode="Off" /> so that you get an ugly stack trace telling you more information. Your question is unanswerable given that Internal Server Error could mean absolutely anything :/ Commented Aug 10, 2014 at 12:16
  • Try to send your data without stringifying it... Commented Aug 10, 2014 at 12:19
  • @L.B sending the data without the stringify gives the same error (500) Commented Aug 10, 2014 at 12:24

1 Answer 1

2

Thank you all for your support. I was able to solve this by changing the parameter data type from string to Object.

 public string RecieveData(Object data)
{

    return "";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.