从ajax调用调试c#webmethod?

时间:2016-08-18 15:55:06

标签: c# jquery asp.net ajax

我有一个asp.net(网络表单)c#代码页面后面有一个web方法,我在同一页面上从ajax调用调用。

我收到通用"发生内部服务器错误"在ajax POST调用之后。

我想通过网络方法代码来确定发生了什么。

我该怎么做?断点没有被击中。我必须附加一个过程吗?我无法找到有关处理WebMethod调用的本地IIS上运行的进程的任何信息?

注意:我可以调试并逐步执行常规事件响应功能,例如Page_Load和其他功能。

ajax代码:

 $.ajax({
    type: "POST",
    url: "/Patrol/Report.aspx/GetSPResults",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: JSON.stringify(postData)
}).done(function (result) {
    var results = "";
    if (result.d.length > 0) {
        results = JSON.parse(result.d);
    }
    buildViewModel(results);
    kendo.bind($("#Report"), viewModel);
    $("Checkpoints").fadeIn(100);
}).fail(function (jqXHR, textStatus, err) {
    alert("An error has occurred: " + err);
});

网络方法:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string GetSPResults(string reportId, string sproc, Dictionary<string, string> parameters, string[] ensureArrays)
{
    Int32 intReportId;
    Console.WriteLine("Report.aspx/GetSPResults called");
    if (Int32.TryParse(reportId, out intReportId))
    {
        AV.Data.SqlSPHelper avdata = new AV.Data.SqlSPHelper(ConfigurationManager.ConnectionStrings["ProductionConnectionString"].ConnectionString);
        Dictionary<string, string> sprocCheckParams = new Dictionary<string, string>()
        {
            {"Sproc", sproc},
            {"ReportID", reportId}
        };
        XElement sprocCheck = avdata.ExecuteSPXmlXElement("[dw].[spReport_Sproc_Check]", sprocCheckParams, null);
        if (sprocCheck.GetAttributeVal("result") == "1")
        {
            XElement result = avdata.ExecuteSPXmlXElement(sproc, parameters, null);
            result = result?.RemoveAllNamespacesAndNils();
            if (result != null)
            {
                var jsonResults = JsonConvertWrapper.SerializeXelement(result, ensureArrays, true, Formatting.Indented, true);
                return jsonResults;
            }
        }
    }
    return string.Empty;
}

1 个答案:

答案 0 :(得分:0)

好的问题是我的帖子请求的参数名称与WebMethod函数签名中的参数名称不匹配。

当WebMethod期望reportID

时,POST请求的参数名称为reportId
相关问题