我正在尝试使用带有复杂对象作为输入的 jQuery 调用 ASP Web 服务。
这是我的 jQuery fn:
request: function (url, method, data) {
var json = JSON.stringify(data);
return $.ajax({
url: url,
type: method,
data: json,
error: ErrorHelpers.printErrorToConsole,
dataType: 'json',
contentType: 'application/json',
processData: false
});
}
传入的 json 如下所示:
{
"search": {
"WarehouseId": "",
"AuctionId": "",
"Barcode": "",
"Name": "",
"CategoryId": "",
"Description": "",
"ManufacturerId": "",
"StatusId": "",
"StatusOperator": "",
"HasPhoto": "",
"DateReceived": "",
"SellerAdministrativeArea": "",
"SellerId": "",
"IsApproved": "",
"Keyword": "",
"SortBy": "",
"RowStart": "",
"RowLimit": "10"
}
}
我的网络方法定义如下:
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public List<ClientInventory> GetInventory(string search)
{ //code
}
有谁知道为什么会出错?这是我得到的回复:
{"Message":"无效的 Web 服务调用,缺少参数值:\u0027search\u0027。","StackTrace":" at System.Web.Script.Services.WebServiceMethodData.CallMethod(对象目标,IDictionary
2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary
2 参数)\r \n 在 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.InvalidOperationException"}