WebServiceProxy.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // WebServiceProxy.js
  2. var webMethod;
  3. var webServicePath;
  4. // This function shows how to use the
  5. // WebServiceProxy.invoke method without passing
  6. // parameters.
  7. function GetTime()
  8. {
  9. Sys.Net.WebServiceProxy.invoke(webServicePath,
  10. webMethod, false,{}, OnSucceeded,
  11. OnFailed,"User Context",1000000);
  12. }
  13. // This function shows how to use the
  14. // invoke method passing
  15. // parameters and using the GET verb.
  16. // The dictionary field names must match the
  17. // related Web service method parameter names.
  18. function GetGreetings()
  19. {
  20. Sys.Net.WebServiceProxy.invoke(webServicePath,
  21. webMethod, true,
  22. {"greeting":"Have a nice day", "name":" to You (via GET)!"},
  23. OnSucceeded,OnFailed, "User Context",100);
  24. }
  25. // This function shows how to use the
  26. // invoke method passing parameters and using the POST verb.
  27. // The dictionary field names must match the
  28. // related Web service method parameter names.
  29. function PostGreetings()
  30. {
  31. Sys.Net.WebServiceProxy.invoke(webServicePath,
  32. webMethod, false,
  33. {"greeting":"Have a nice day", "name":" to You (via POST)!"},
  34. OnSucceeded,OnFailed, "User Context",100);
  35. }
  36. // This is the callback function invoked
  37. // if the Web service succeeded.
  38. function OnSucceeded(result, eventArgs)
  39. {
  40. // Display the result.
  41. var RsltElem =
  42. document.getElementById("ResultId");
  43. RsltElem.innerHTML = result;
  44. }
  45. // This is the callback function invoked
  46. // if the Web service failed.
  47. function OnFailed(error)
  48. {
  49. // Display the error.
  50. var RsltElem =
  51. document.getElementById("ResultId");
  52. RsltElem.innerHTML =
  53. "Service Error: " + error.get_message();
  54. }
  55. // This function process the user's selection.
  56. function OnSelectMethod()
  57. {
  58. // Get the user's selected method.
  59. var selectionIndex =
  60. document.getElementById("SelectionId").selectedIndex;
  61. webMethod =
  62. document.getElementById("SelectionId").options[selectionIndex].text;
  63. // Get the related Web service path.
  64. webServicePath =
  65. document.getElementById("SelectionId").value;
  66. // Call selected Web service method.
  67. switch (webMethod)
  68. {
  69. case "GetServerTime":
  70. GetTime();
  71. break;
  72. case "GetGreetings":
  73. GetGreetings();
  74. break;
  75. case "PostGreetings":
  76. PostGreetings();
  77. break;
  78. default:
  79. alert("default");
  80. }
  81. }
  82. if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();