| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- // UsingProxyClass.js
- // The Web service default color.
- var defaultRgb;
- // The proxy class instance.
- var proxyInstance;
- // The page feedback display element.
- var displayResult;
- // This function intializes the global variables and
- // assigns default values to the generated proxy.
- function pageLoad()
- {
- // Get page feedback display element.
- displayResult =
- document.getElementById("ResultId");
-
- // Assign default values to the generated proxy.
- Samples.AspNet.UsingProxyClass.set_timeout(200);
- Samples.AspNet.UsingProxyClass.set_defaultUserContext("Default context");
- Samples.AspNet.UsingProxyClass.set_defaultSucceededCallback(SucceededCallback);
- Samples.AspNet.UsingProxyClass.set_defaultFailedCallback(FailedCallback);
- }
- // This function shows how to get
- // a server object.
- function GetDefaultColor()
- {
- // Gets the default color obiect.
- Samples.AspNet.UsingProxyClass.GetDefaultColor();
-
- }
- // This function shows how to instantiate
- // the proxy class to assign its default values.
- function SetColor()
- {
- // Instantiate a color object.
- var color =
- new Samples.AspNet.ColorObject();
- // Define a color array (blue).
- var colorArray = new Array("00", "00", "FF");
- // Assign the new values to the server color object.
- color.message = "The new color is Blue";
- color.rgb = colorArray;
-
-
- // Assign default values for the generated proxy using
- // a proxy instance.
- proxyInstance = new Samples.AspNet.UsingProxyClass();
- proxyInstance.set_timeout(1000);
- proxyInstance.set_defaultUserContext("New context");
- proxyInstance.set_defaultSucceededCallback(SucceededCallback);
- proxyInstance.set_defaultFailedCallback(FailedCallback);
-
- // Set the default color object.
- proxyInstance.SetColor(color);
- }
- // Callback function invoked when the call to
- // the Web service methods succeeds.
- function SucceededCallback(result, userContext, methodName)
- {
- var message;
- switch(methodName)
- {
- case ("GetDefaultColor"):
- case ("SetColor"):
- {
- // Get the server default color.
- message = result.message;
- defaultRgb = result.rgb;
-
-
- // Transform the rgb array into a string.
- var serverColor = defaultRgb[0]+ defaultRgb[1] + defaultRgb[2];
-
- // Display the result.
- displayResult.style.color = "yellow";
- displayResult.style.fontWeight = "bold";
- displayResult.style.backgroundColor = "#" + serverColor;
- DisplayMessage(message);
- break;
- }
- default:
- {
- DisplayMessage("Method unknown");
- }
- }
- }
- // Callback function invoked when the call to
- // the Web service methods fails.
- function FailedCallback(error, userContext, methodName)
- {
- if(error !== null)
- {
- displayResult.innerHTML = "An error occurred: " +
- error.get_message();
- }
- }
- function DisplayMessage(message)
- {
- if (document.all)
- displayResult.innerText = message;
- else
- // Firefox
- displayResult.textContent = message;
- }
- if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
|