我正在尝试将字符串发送File
到我的 asmx 服务,但我不断收到以下错误:
Message: Invalid web service call, missing value for parameter: File
StackTrace
at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters) 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.InvalidOperationException\"}
这是JS
function AJAXActionPostData(service, operation, File, callback, async)
{
if (!async) { async = false; }
$.ajax({
type: 'POST',
url: '/API/Service.asmx/operation',
contentType: 'application/json; charset=utf-8',
async: async,
data: "{ 'File': '" + File + "' }",
dataType: 'json',
success: function (msg) { if (msg) { callback(msg.d); } },
error: ErrorHandler
});
}
当传递给上面的函数时,file
它的值为“test\r\n”转义字符会不会弄乱它?
服务代码
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool UploadCSV(string id, string File)
{
string testfile = File;
return true;
}
没有其他错误被抛出,只是File
没有值。我尝试了各种事情,但无法理解我错过了什么?