- Home
- Tutorials
- Flash
- Intermediate
- Flash Remoting & FlashCom Server

Services
Copyright © 2004 O'Reilly Media, Inc. All Rights Reserved. | ![]() |
| This content is excerpted from the above-named O'Reilly publication, with permission, by agreement with ActionScript.org. | |
The syntax to access remote services varies slightly depending on the Flash Remoting gateway version (ColdFusion, Java, .NET, etc.). Furthermore, the types of services available via Remoting vary slightly as well. For example, accessing a remote web service via Java or JRun requires a wrapper, which is not necessary with ColdFusion or .NET. Once connected to a service, however, the service's methods are accessed from the client code in a uniform way that is independent of the Flash Remoting gateway or the server-side technology implementing the remote services.
To provide access to its services, the remote application server supports a service class, which provides access to one or more remote methods. The techniques required to define a service class vary, so check the documentation of your server (ColdFusion, .NET, Java, etc.) or consult Flash Remoting: The Definitive Guide. For our purposes, we assume you have created a remote application and properly configured your application server to allow remote access to it.
Connecting to a remote service class (or simply a service) is accomplished by supplying the service's dot-delimited path to the getService( ) method. This path is typically the full path from the web root of the server. Some server implementations such as ColdFusion, JRun, and AMFPHP provide a mechanism to specify a classpath or a service directory, in which case the service path supplied can be relative to that location.
The syntax for most of the remote services requires that you omit the file extension of the service class file. For example, here, we omit the .cfml or .cfc extension of a ColdFusion service:
UtilityService = my_conn.getService("cfcs.jwatkins.CommonUtils");
Web services are supported by many of the remoting implementations. Example 11-2 illustrated how to connect to the Google search web service. Connecting to a web service is as simple as specifying the .wsdl file as the service name passed to getService( ):
TempService = my_conn.getService(
"http://www.xmethods.net/sd/2001/TemperatureService.wsdl");
A single connection object can be shared for all services located at a gateway URL.
Tip
Flash Remoting calls are batched together when the Flash client makes multiple remote calls on the same frame or when FlashCom makes multiple remote calls from within the same function. When calls are batched, you do not receive a response from any method calls until all of the remote methods have finished.
The following two remote calls are batched together even though one is mapped to a local service class and the other is a web service. The results are not returned from the remoting server until both of the methods have completed processing:
someFunction = function ( ) {
NetServices.setDefaultGatewayUrl("http://localhost/flashservices/gateway");
my_conn = NetServices.createGatewayConnection( );
UtilityService = my_conn.getService("cfcs.jwatkins.CommonUtils");
TempService = my_conn.getService(
"http://www.xmethods.net/sd/2001/TemperatureService.wsdl");
UtilityService.searchString(needle, haystack);
TempService.getTemp("61310");
};
This automated batching of remote calls is an important issue that may impact your implementation of performing remote calls. If a remote method takes a long time to execute or returns a large amount of data, it will slow other processes down. So you should ensure that such methods execute separately from other methods. This can be accomplished by chaining the remote calls (i.e., waiting for the results of one before executing another) or by using separate connection objects for each method call. Here is an example using separate connections:
someFunction = function ( ) {
NetServices.setDefaultGatewayUrl("http://localhost/flashservices/gateway");
my_conn1 = NetServices.createGatewayConnection( );
my_conn2 = NetServices.createGatewayConnection( );
UtilityService = my_conn1.getService("cfcs.jwatkins.CommonUtils");
TempService = my_conn2.getService(
"http://www.xmethods.net/sd/2001/TemperatureService.wsdl");
UtilityService.searchString(needle, haystack);
TempService.getTemp("61310");
};

