How to pass parameters to Web Service

Last post 07-08-2009 8:53 PM by mrmercury. 6 replies.

Sort Posts:

  • How to pass parameters to Web Service

    07-08-2009, 1:07 PM
    • Member
      21 point Member
    • MAW74656
    • Member since 07-08-2009, 4:56 PM
    • Posts 26

    Hey guys. I am a student and new to AJAX programming in general, so forgive me if my questions are simple or non-sensical.

    I have a web service as follows (C# code-behind): [WebMethod] public string AddCardToDatabase(String playerName, String team, String year, String ownerID) { //body ommitted due to irrelevence }

    And I have Javascript as follows: function () { var player = $get('txtPlayerName').value; var team = $get('txtTeam').value; var year = $get('txtYear').value; var userID = $get(val).value; //Clear the text boxes. $get('txtPlayerName').value = ""; $get('txtTeam').value = ""; $get('txtYear').value = ""; CardService.AddCardToDatabase(player, team, year, userID, onComplete, onFailure); } function onComplete(arg) { $get('response').innerHTML = arg + "
    Please add your next card."; document.getElementById("UpdatePanel1").update(); } function onFailure() { alert("We are sorry, but your request could not be completed."); }

    I've tested, and all the variables I'm attempting to pass as parameters do have values. Also I know the web service is being called and can respond, but why does it keep calling the onFailure method??

    Any suggestions you can make would be appreciated.

  • Re: How to pass parameters to Web Service

    07-08-2009, 6:15 PM
    • Star
      13,543 point Star
    • gt1329a
    • Member since 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 2,237
    • TrustedFriends-MVPs

    If it's hitting the OnFailure callback, your web service is probably returning a 500 error.  Run it in debug mode in Visual Studio and you should be able to see why.

    Or, inspect the response in something like Firebug or Fiddler.  It should contain some detail on the 500 error.

    Encosia - ASP.NET, jQuery, AJAX, and more.

    Latest article: Emulate ASP.NET validation groups with jQuery validation
  • Re: How to pass parameters to Web Service

    07-08-2009, 6:20 PM
    • Contributor
      5,082 point Contributor
    • mrmercury
    • Member since 04-04-2006, 2:26 PM
    • Mexico City, Mexico
    • Posts 739

    There can be any number of reasons for this, you should use the get_message() method of the error object in your onFailure function to get some info.

    If this post helped you please remember to set it as Answer so it can help others.
  • Re: How to pass parameters to Web Service

    07-08-2009, 8:23 PM
    • Member
      21 point Member
    • MAW74656
    • Member since 07-08-2009, 4:56 PM
    • Posts 26

    Ok, sounds logical, but I'm unsure how to do this for the following reasons:

    1. First I should change my method signature to: function onFailure(arg) { } so that it excepts the error object?

    2. Then you suggest calling the get_message() method of the error object, however Intellisense doesn't recognize that. Could you recommend the statement I should use?

  • Re: How to pass parameters to Web Service

    07-08-2009, 8:27 PM
    • Member
      21 point Member
    • MAW74656
    • Member since 07-08-2009, 4:56 PM
    • Posts 26

    You suggest I run in debug mode, am I watching what happens in the web service? Should I put breakpoints in the service method?

  • Re: How to pass parameters to Web Service

    07-08-2009, 8:42 PM
    • Star
      13,543 point Star
    • gt1329a
    • Member since 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 2,237
    • TrustedFriends-MVPs

    You shouldn't even have to set a breakpoint, if it's throwing an error.  When you call the service, the debugger should receive focus and show you the error.

    Encosia - ASP.NET, jQuery, AJAX, and more.

    Latest article: Emulate ASP.NET validation groups with jQuery validation
  • Re: How to pass parameters to Web Service

    07-08-2009, 8:53 PM
    Answer
    • Contributor
      5,082 point Contributor
    • mrmercury
    • Member since 04-04-2006, 2:26 PM
    • Mexico City, Mexico
    • Posts 739

    Generally the signature would be: function onFailure(error)  {}, and then you could use something like this inside the function: alert(error.get_message());

    If this post helped you please remember to set it as Answer so it can help others.
Page 1 of 1 (7 items)