我在向.NET Web服务提交复杂的JSON对象时遇到问题。
Ajax JavaScript代码:
$.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);
}
});
.NET webservice
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string RecieveData(string data)
{
return "";
}
尝试从客户端向Web服务提交数据时,我收到内部服务器错误500 。
我有其他webservice函数只返回数据,它们工作正常。我在web.config中给出了GET和POST权限。
这是详细的错误:
"{"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"}"
感谢。
答案 0 :(得分:2)
谢谢大家的支持。我能够通过将参数数据类型从字符串更改为Object来解决此问题。
public string RecieveData(Object data)
{
return "";
}