CallWebServiceMethods.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // CallWebServiceMethods.js
  2. // This function calls the Web service method without
  3. // passing the callback function.
  4. function GetNoReturn()
  5. {
  6. Samples.AspNet.WebService.GetServerTime();
  7. alert("This method does not return a value.");
  8. }
  9. // This function calls the Web service method and
  10. // passes the event callback function.
  11. function GetTime()
  12. {
  13. Samples.AspNet.WebService.GetServerTime(
  14. SucceededCallback);
  15. }
  16. // This function calls the Web service method
  17. // passing simple type parameters and the
  18. // callback function
  19. function Add(a, b)
  20. {
  21. Samples.AspNet.WebService.Add(a, b,
  22. SucceededCallback);
  23. }
  24. // This function calls the Web service method
  25. // that returns an XmlDocument type.
  26. function GetXmlDocument()
  27. {
  28. Samples.AspNet.WebService.GetXmlDocument(
  29. SucceededCallbackWithContext, FailedCallback,
  30. "XmlDocument")
  31. }
  32. // This function calls a Web service method that uses
  33. // GET to make the Web request.
  34. function MakeGetRequest()
  35. {
  36. Samples.AspNet.WebService.EchoStringAndDate(
  37. new Date("1/1/2007"), " Happy",
  38. SucceededCallback,
  39. FailedCallback, "HappyNewYear");
  40. }
  41. // This is the callback function invoked if the Web service
  42. // succeeded.
  43. // It accepts the result object, the user context, and the
  44. // calling method name as parameters.
  45. function SucceededCallbackWithContext(result, userContext, methodName)
  46. {
  47. var output;
  48. // Page element to display feedback.
  49. var RsltElem = document.getElementById("ResultId");
  50. var readResult;
  51. if (userContext == "XmlDocument")
  52. {
  53. if (document.all)
  54. readResult =
  55. result.documentElement.firstChild.text;
  56. else
  57. // Firefox
  58. readResult =
  59. result.documentElement.firstChild.textContent;
  60. RsltElem.innerHTML = "XmlDocument content: " + readResult;
  61. }
  62. }
  63. // This is the callback function invoked if the Web service
  64. // succeeded.
  65. // It accepts the result object as a parameter.
  66. function SucceededCallback(result, eventArgs)
  67. {
  68. // Page element to display feedback.
  69. var RsltElem = document.getElementById("ResultId");
  70. RsltElem.innerHTML = result;
  71. }
  72. // This is the callback function invoked if the Web service
  73. // failed.
  74. // It accepts the error object as a parameter.
  75. function FailedCallback(error)
  76. {
  77. // Display the error.
  78. var RsltElem =
  79. document.getElementById("ResultId");
  80. RsltElem.innerHTML =
  81. "Service Error: " + error.get_message();
  82. }
  83. if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();