Invalid web service call, missing value for parameter
10,214
Try sending with processData: false
in your ajax params. jQuery will stringify again by default.
Use fiddler or similar tool to inspect network traffic and see what is getting actually sent to your web service.
Comments
-
makeitmorehuman almost 2 years
I have been looking at this for a while and can't see where the problem is. Any help is greatly appreciated.
[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; } }); }
And I get:
{"Message":"Invalid web service call, missing value for parameter: \u0027force\u0027.","StackTrace":"
-
makeitmorehuman almost 13 yearsI removed the stringify and allowed jquery to process data. what is being sent to the service is: force sussex neighbourhood CC2NH7 but now I get invalid json primitive.
-
Mrchief almost 13 yearsTry this: stringify yourself, and set processData to false.
-
makeitmorehuman almost 13 yearsI stringify myself and set the processData to false. what I get now is {"Message":"Invalid web service call, missing value for parameter: \u0027force\u0027.","StackTrace":" The Params sent are now: {"force":"sussex","neighb...
-
makeitmorehuman almost 13 yearsShould I be renaming aspx of the service as asmx?
-
Mrchief almost 13 yearsGood catch! I didn't notice that earlier. Change it to asmx. Are you using any tools like fiddler? ALso, if you attach a debugger, does it come to your method or it throws the exception even before that?
-
makeitmorehuman almost 13 yearsNow its all working but only locally and I get “401 Unauthorized” on the server. I hope its not becuase I haven't included <httpHandlers> <add verb="" path=".asmx" type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/> </httpHandlers> if this is the issue how can I get around it without adding it. its a shared server and doesn't let me add httpmodules
-
makeitmorehuman almost 13 yearsI am also calling the service from a normal html page not an aspx. is this an issue?
-
Mrchief almost 13 yearsCalling it from html should no be an issue. The other problem you have should be a separate question (I'm not an expert but I guess it should be).