发送JSON对象到.net webservice时出现内部服务器错误
本文关键字:内部 服务器 错误 webservice JSON 对象 net 发送 | 更新日期: 2023-09-27 18:17:31
我在向。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 "";
}
我得到一个内部服务器错误500当试图从客户端提交数据到webservice。
我有其他的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"}"
谢谢。
感谢大家的支持。我可以通过将参数数据类型从string更改为Object来解决这个问题。
public string RecieveData(Object data)
{
return "";
}