admin管理员组

文章数量:1392081

I'm trying to send the string File to my asmx service and I keep getting the following error:

    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\"}

Here's the 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
    });
}

when passed into the function above file has a value of "test\r\n" Could the escape characters be messing with it?

Service code

    [WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public bool UploadCSV(string id, string File)
    {
        string testfile = File;
        return true;
    }

No other errors are thrown, just the File not having a value. I've tried various things but cannot understand what I'm missing?

I'm trying to send the string File to my asmx service and I keep getting the following error:

    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\"}

Here's the 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
    });
}

when passed into the function above file has a value of "test\r\n" Could the escape characters be messing with it?

Service code

    [WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public bool UploadCSV(string id, string File)
    {
        string testfile = File;
        return true;
    }

No other errors are thrown, just the File not having a value. I've tried various things but cannot understand what I'm missing?

Share Improve this question asked Sep 4, 2013 at 16:05 AlexAlex 8283 gold badges13 silver badges26 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 5

Try sending the data as a plain object:

data: { 'File': File },

Or as a string:

data: 'File=' + File,

At the moment you're doing a little of both which won't work.

本文标签: javascriptMissing parameter in Ajax post to AsmxStack Overflow