Name

NetConnection.getService( ) Method

Synopsis

                     myNetConnectionObject.getService(serviceName, defaultResponder)

Arguments

serviceName

The name of the remote service whose methods you want to access. This varies according to the server model and the type of service you are accessing, as documented in earlier chapters.

defaultResponder

An optional responder object that handles the responses and errors with defined onResult( ) and onStatus( ) methods. If you don’t specify the defaultResponder, you must specify responders in your method calls.

Returns

A NetServiceProxy object.

Description

The getService( ) method is used to create a proxy to a remote service and is one of the most frequently used NetConnection methods. The call to getService( ) returns a NetServiceProxy object, which dispatches responses from the service to the client, as discussed in Chapter 4.

Example

The following code shows the basic syntax of the getService( ) method:

#include "NetServices.as"
onResult = function (myResult) {
  results_txt.text = myResult;
};

onStatus = function (myError) {
  results_txt.text = myError.description;
};
var servicePath = "com.oreilly.frdg.HelloUser";
NetServices.setDefaultGatewayURL("http://localhost/flashservices/gateway");
var my_conn = NetServices.createGatewayConnection( );
var my_service = my_conn.getService(servicePath, this);
my_service.sayHello(firstname_txt.text);

The first parameter passed to getService( ) must be the properly formed service name, as discussed at length in Chapter ...

Get Flash Remoting: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.