This Quick Start guide contains information pertaining to:
The Flash client performs a method invocation on a C# class deployed into WebORB. The class used in this guide can be found below and has public method. The method collects basic information about the computer and returns it back. Source code and compiled class files for this Quick Start guide can be found in:
/wwwroot/weborb/examples/quickstart/flash - contains the client side
code
/wwwroot/weborb/examples/quickstart/server-side - contains the server side
code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// copyright 2003 - 2004
Midnight Coders, LLC using System; using System.Web; using Weborb.Util; namespace weborb.examples.quickstart { public class ComputerInfoService { public ComputerInfo getComputerInfo( String requestId ) { ComputerInfo computerInfo = new ComputerInfo(); HttpRequest request = ThreadContext.currentRequest() computerInfo.serverName = request.ServerVariables[ "SERVER_SOFTWARE" ]; computerInfo.clrVersion = Environment.Version.ToString(); computerInfo.clrVendor = "Microsoft"; computerInfo.os = Environment.OSVersion.Platform.ToString(); computerInfo.osVersion = Environment.OSVersion.Version.ToString(); computerInfo.requestId = requestId; return computerInfo; } } } |
The ComputerInfo class is defined as:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// copyright 2003 - 2004
Midnight Coders, LLC using System; namespace weborb.examples.quickstart { public class ComputerInfo { internal string serverName; internal string clrVersion; internal string clrVendor; internal string os; internal string osVersion; internal string requestId; } } |
Flash client development requires an installation of Flash Remoting Components. The components are available for a free download from the Macromedia web site. The sample client developed for this guide uses Flash Remoting components for ActionScript 2.0, but the code can be easily refactored to use the ActionScript 1.0 approach.
When browser loads the Flash movie, the Flash plug-in executes the following script from the first frame of the movie:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import mx.controls.Alert; import mx.remoting.Service; import mx.remoting.PendingCall; import mx.rpc.FaultEvent; import mx.rpc.ResultEvent; import mx.remoting.debug.NetDebug; NetDebug.initialize(); var reqID = 0; var webORBURL = "http://localhost/weborb/weborb.aspx"; var className = "weborb.examples.quickstart.ComputerInfoService"; var computerInfoService = new Service( webORBURL, null, className, null, null ); getComputerInfo(); function getComputerInfo() { var pendingCall = computerInfoService.getComputerInfo( reqID++ ); pendingCall.responder = new mx.rpc.RelayResponder( this, "computerInfoRetrieved", "callFailed" ); } function computerInfoRetrieved( result : ResultEvent ) { serverName.text = result.result.serverName; javaVersion.text = result.result.javaVersion; javaVendor.text = result.result.javaVendor; os.text = result.result.os; osVersion.text = result.result.osVersion; requestID.text = result.result.requestId; } function callFailed( fault : FaultEvent ) { Alert.show( "Server reported an error : " + fault.fault.description, "Error" ); } var invokeHandler = new Object(); invokeHandler.click = function() { getComputerInfo(); } invokeButton.addEventListener( "click", invokeHandler ); |
The binding call takes place on line 12 and creates a proxy object bound to the server-side class. The movie initiates initial invocation on line 13. The getComputerInfo() function invokes the method on the proxy object and sets up a responder object. As soon as a return value from the invocation becomes available, Flash Remoting Components invoke the computerInfoRetrieved function. If an error occurs or the server object throws an exception, Flash Remoting executes the callFailed function.
The computerInfoRetrieved function populates the text fields on the user interface with the data from the remote method's return value (lines 23-28).
The invokeHandler object is an event handler for the invokeButton button. When a user presses the button, the event handler invokes the getComputerInfo function (line 39).
The complete client application page can be found in /wwwroot/weborb/examples/quickstart/flash. Copy flash-computerinfo.aspx and computerinfo.swf into /wwwroot/weborb. The weborb folder is the document root for the WebORB ASP.NET application.
Open web browser and point to http://localhost/weborb/flash-computerinfo.aspx.
The Flash client application is loaded, binds to the server object, invokes the method and displays data from the response.