【问题标题】:Invalid web service call, missing value for parameter无效的 Web 服务调用,缺少参数值
【发布时间】:2011-09-22 05:46:19
【问题描述】:

我已经查看了一段时间,但看不出问题出在哪里。非常感谢任何帮助。

[WebMethod(true)]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public static string neighbourhoodTeam(string force, string neighbourhood) 
{
    //StreamManager streamMan = new StreamManager();
    //return streamMan.StreamManagerUrlHandler("http://policeapi2.rkh.co.uk/api/" + force + "%2F" + neighbourhood + "%2F" + "people");
    return neighbourhood + force;
}

jQuery:

function getOfficers(force, neighbourhood) {
    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: "../police/crimerequest.aspx/neighbourhoodTeam",
        data: JSON.stringify({ "force": force, "neighbourhood": neighbourhood }),
        dataType: "json",
        success: function (data) {
            var results = $.parseJSON(data.d);
            $.each(results, function (i) {
                businessCards.push(generateOfficerBusinessCard(
                            results[i].name,
                            results[i].rank,
                            results[i].contact_details.mobile,
                            results[i].contact_details.tel,
                            results[i].contact_details.email))
            });
            PoliceApp.businessCardsPlaceHolder.html(businessCards.toString());
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
            alert(xhr.responseText);
            return false;
        }
    });
}

我得到:{"Message":"Invalid web service call, missing value for parameter: \u0027force\u0027.","StackTrace":"

【问题讨论】:

    标签: jquery asp.net ajax webmethod


    【解决方案1】:

    尝试在您的 ajax 参数中使用 processData: false 发送。 jQuery 默认会再次字符串化。

    使用 fiddler 或类似工具检查网络流量并查看实际发送到您的网络服务的内容。

    【讨论】:

    • 我删除了 stringify 并允许 jquery 处理数据。发送到服务的内容是:强制苏塞克斯社区 CC2NH7 但现在我得到无效的 json 原语。
    • 试试这个:字符串化自己,并将 processData 设置为 false。
    • 我将自己字符串化并将 processData 设置为 false。我现在得到的是 {"Message":"Invalid web service call, missing value for parameter: \u0027force\u0027.","StackTrace":" 发送的参数现在是:{"force":"sussex","neighb ...
    • 我应该将服务的 aspx 重命名为 asmx 吗?
    • 好收获!我之前没有注意到这一点。将其更改为 asmx。您是否使用任何工具,如提琴手?另外,如果你附加了一个调试器,它会出现在你的方法中还是在此之前抛出异常?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-28
    相关资源
    最近更新 更多