3

文字列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。いろいろ試してみたのですが、何が足りないのかわかりませんか?

4

1 に答える 1

5

dataをプレーンなオブジェクトとして送信してみてください:

data: { 'File': File },

または文字列として:

data: 'File=' + File,

現時点では、両方を少し実行していますが、うまくいきません。

于 2013-09-04T16:07:58.597 に答える