【发布时间】:2013-09-04 16:05:31
【问题描述】:
我正在尝试将字符串 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 没有值。
我尝试了各种方法,但无法理解我缺少什么?
【问题讨论】:
标签: javascript jquery ajax web-services asmx