UsingProxyClass.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // UsingProxyClass.js
  2. // The Web service default color.
  3. var defaultRgb;
  4. // The proxy class instance.
  5. var proxyInstance;
  6. // The page feedback display element.
  7. var displayResult;
  8. // This function intializes the global variables and
  9. // assigns default values to the generated proxy.
  10. function pageLoad()
  11. {
  12. // Get page feedback display element.
  13. displayResult =
  14. document.getElementById("ResultId");
  15. // Assign default values to the generated proxy.
  16. Samples.AspNet.UsingProxyClass.set_timeout(200);
  17. Samples.AspNet.UsingProxyClass.set_defaultUserContext("Default context");
  18. Samples.AspNet.UsingProxyClass.set_defaultSucceededCallback(SucceededCallback);
  19. Samples.AspNet.UsingProxyClass.set_defaultFailedCallback(FailedCallback);
  20. }
  21. // This function shows how to get
  22. // a server object.
  23. function GetDefaultColor()
  24. {
  25. // Gets the default color obiect.
  26. Samples.AspNet.UsingProxyClass.GetDefaultColor();
  27. }
  28. // This function shows how to instantiate
  29. // the proxy class to assign its default values.
  30. function SetColor()
  31. {
  32. // Instantiate a color object.
  33. var color =
  34. new Samples.AspNet.ColorObject();
  35. // Define a color array (blue).
  36. var colorArray = new Array("00", "00", "FF");
  37. // Assign the new values to the server color object.
  38. color.message = "The new color is Blue";
  39. color.rgb = colorArray;
  40. // Assign default values for the generated proxy using
  41. // a proxy instance.
  42. proxyInstance = new Samples.AspNet.UsingProxyClass();
  43. proxyInstance.set_timeout(1000);
  44. proxyInstance.set_defaultUserContext("New context");
  45. proxyInstance.set_defaultSucceededCallback(SucceededCallback);
  46. proxyInstance.set_defaultFailedCallback(FailedCallback);
  47. // Set the default color object.
  48. proxyInstance.SetColor(color);
  49. }
  50. // Callback function invoked when the call to
  51. // the Web service methods succeeds.
  52. function SucceededCallback(result, userContext, methodName)
  53. {
  54. var message;
  55. switch(methodName)
  56. {
  57. case ("GetDefaultColor"):
  58. case ("SetColor"):
  59. {
  60. // Get the server default color.
  61. message = result.message;
  62. defaultRgb = result.rgb;
  63. // Transform the rgb array into a string.
  64. var serverColor = defaultRgb[0]+ defaultRgb[1] + defaultRgb[2];
  65. // Display the result.
  66. displayResult.style.color = "yellow";
  67. displayResult.style.fontWeight = "bold";
  68. displayResult.style.backgroundColor = "#" + serverColor;
  69. DisplayMessage(message);
  70. break;
  71. }
  72. default:
  73. {
  74. DisplayMessage("Method unknown");
  75. }
  76. }
  77. }
  78. // Callback function invoked when the call to
  79. // the Web service methods fails.
  80. function FailedCallback(error, userContext, methodName)
  81. {
  82. if(error !== null)
  83. {
  84. displayResult.innerHTML = "An error occurred: " +
  85. error.get_message();
  86. }
  87. }
  88. function DisplayMessage(message)
  89. {
  90. if (document.all)
  91. displayResult.innerText = message;
  92. else
  93. // Firefox
  94. displayResult.textContent = message;
  95. }
  96. if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();