Недопустимый вызов веб-службы, отсутствует значение параметра - PullRequest
4 голосов
/ 24 июня 2011

Я давно смотрю на это и не вижу, в чем проблема. Любая помощь с благодарностью.

[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":"

1 Ответ

5 голосов
/ 24 июня 2011

Попробуйте отправить с processData: false в ваших параметрах ajax.По умолчанию jQuery снова преобразуется в строку.

Используйте fiddler или аналогичный инструмент для проверки сетевого трафика и просмотра того, что фактически отправляется на ваш веб-сервис.

...