View comments | RSS feed

mx.remoting
Class NetServices



class NetServices
extends Object

Note: The NetServices class and its methods are deprecated in Flash Remoting for Flash MX 2004 in favor of the Service class. For more information, see mx.remoting.Service. Note: You cannot use the PendingCall or RelayResponder classes with the NetServices class to handle results or fault conditions that are returned from service functions. For information on how to handle results and fault conditions with the NetServices class, see Using NetServices and Connection Classes. The NetServices class is for Flash Remoting use only. The NetServices class is a collection of methods that helps you create and use connections to services using Flash Remoting. You can import the NetServices class using the following import statement:

   import mx.remoting.NetServices;
   

See Also
    mx.remoting.Service



Methods
staticcreateGatewayConnection( url: String, log: Log)  : Connection
Establishes the required connection information for communication to the gateway.
staticgetConnection( uri: String)  : Connection
Returns a Connection object for the specified URL from a pool of shared connections.
staticgetHostUrl( )  : String
Returns a string containing the hostname and port of the URL that contains the current SWF file, without a trailing /.
staticgetHttpUrl( url: String)  : String
Converts a relative URL to a full URL by prepending the hostname, if the provided URL is a non-HTTP URL.
staticsetDefaultGatewayUrl( url: String)  : Void
Sets the default URL that Flash Remoting uses when it executes the createGatewayConnection() method and you do not otherwise specify the gateway URL.
staticsetGatewayUrl( url: String)  : Void
Specifies the URL to be used for a Flash Remoting gateway connection.


Properties
staticversion: String
Component version.


Method Detail

createGatewayConnection

static  createGatewayConnection( url: String, log: Log)  : Connection

Establishes the required connection information for communication to the gateway. The Flash application connects only when you actually make a Flash Remoting service function call.

Parameters
    url: String - containins the Flash Remoting gateway URL.
    log: Log - [optional] logger used to capture messages generated during this method invocation Note: this parameter is for internal use only

Returns
    A new Connection object for the connection to the gateway URL, specified in one of the following ways:

  1. The specified URL.
  2. If no URL is specified, the URL specified in the setDefaultGatewayUrl() method is used if it is invoked with a valid URL prior to this method.
  3. The URL that was set using the setGatewayURL() method if it is invoked with a valid URL prior to the createGatewayConnection() method

Example
The following example creates a Connection object for connecting to the Flash Remoting gateway:
   import mx.remoting.NetServices;
   import mx.remoting.NetServiceProxy;
   import mx.remoting.Connection;
   //   var conn:Connection = NetServices.createGatewayConnection(
     "http://localhost:8300/flashservices/" );
   var custService:NetServiceProxy = conn.getService( "customerData" );
   

See Also
    mx.remoting.Connection.connect
    mx.remoting.Service.Service


getConnection

static  getConnection( uri: String)  : Connection

Returns a Connection object for the specified URL from a pool of shared connections. If no connection is found that matched the URL specified, it returns null. Connections are added to the pool by calling the createGatewayConnection() method.

Parameters
    uri: String - A string that specifies the location of the gateway.

Returns
    A connection object with the specified URL or a null value if no connection is found. The connection is retrieved from a shared pool of connections.

Example
The following example illustrates the use of getConnection:
   import mx.remoting.NetServices;
   import mx.remoting.NetServiceProxy;
   import mx.remoting.Connection;
   // we want to share this connection to batch requests to the server
   var conn:Connection = NetServices.getConnection("http://localhost:8300/
       flashservices/");
   // if we don't have one yet, let's create it!
   if( conn == null )
     conn = NetServices.createGatewayConnection("http://localhost:8300/
       flashservices/");
     var custService:NetServiceProxy = conn.getService( "customerData" );
   // ... 
   

See Also
    mx.remoting.Service.Service
    mx.remoting.Connection.connect
    mx.remoting.NetServices.setDefaultGatewayUrl
    mx.remoting.NetServices.setGatewayUrl


getHostUrl

static  getHostUrl( )  : String

Returns a string containing the hostname and port of the URL that contains the current SWF file, without a trailing /. Returns a value of null if the URL does not begin with http:. For example, if the SWF file URL is http:, the function returns http:.

Returns
    A string that specifies the hostname and port.

Example
In the following example, the NetServices.getHostUrl() method extracts from a URL like "http://my.foo.com:1234/some/thing/my.swf" a hostname and port like "http//my.foo.com:1234" and appends the string "/images/customer.jpg":
   var host:String = NetServices.getHostUrl();
   loader.source = host + "/images/customer.jpg";
   

See Also
    mx.remoting.NetServices.getConnection
    mx.remoting.NetServices.getHttpUrl
    mx.remoting.NetServices.setGatewayUrl


getHttpUrl

static  getHttpUrl( url: String)  : String

Converts a relative URL to a full URL by prepending the hostname, if the provided URL is a non-HTTP URL.

Parameters
    url: String - A string that specifies the URL to be converted.

Returns
    A string that contains the full URL.

Example
The following example prepends a hostname to the string provided in the parameter ("/images/cust") to obtain a full URL such as "http://my.foo.com:1234/images/cust":
   loader.source = NetServices.getHttpUrl("/images/cust");
   

See Also
    mx.remoting.NetServices.getConnection
    mx.remoting.NetServices.getHostUrl
    mx.remoting.NetServices.setGatewayUrl


setDefaultGatewayUrl

static  setDefaultGatewayUrl( url: String)  : Void

Sets the default URL that Flash Remoting uses when it executes the createGatewayConnection() method and you do not otherwise specify the gateway URL.

Parameters
    url: String - The default URL to be set.

Example
The following example calls the setDefaultGatewayUrl() method to establish the gateway that will be used by the createGatewayConnection() method:
   import mx.remoting.NetServices;
   import mx.remoting.NetServiceProxy;
   import mx.remoting.Connection;
   // set the default gateway
   NetServices.setDefaultGatewayUrl("http://localhost:8300/flashservices/" );
   var conn:Connection = NetServices.createGatewayConnection(); // connect
   var custService:NetServiceProxy = conn.getService( "customerData" );
   

See Also
    mx.remoting.NetServices.createGatewayConnection
    mx.remoting.NetServices.getHostUrl
    mx.remoting.NetServices.getHttpUrl
    mx.remoting.NetServices.setGatewayUrl


setGatewayUrl

static  setGatewayUrl( url: String)  : Void

Specifies the URL to be used for a Flash Remoting gateway connection.

Parameters
    url: String - A string that specifies a URL that is to be set as the gateway.

Example
The following example calls the setGatewayUrl() method to set the URL that is used by the createGatewayConnection() method:
   import mx.remoting.NetServices;
   import mx.remoting.NetServiceProxy;
   import mx.remoting.Connection;
   // set the gateway Url 
   NetServices.setGatewayUrl("http://localhost:8300/flashservices/" ); 
   var conn:Connection = NetServices.createGatewayConnection(); // connect 
   // create proxy for customerData service 
   var custService:NetServiceProxy = conn.getService( "customerData" );
   

See Also
    mx.remoting.NetServices.createGatewayConnection
    mx.remoting.NetServices.getConnection
    mx.remoting.NetServices.getHostUrl
    mx.remoting.NetServices.getHttpUrl
    mx.remoting.NetServices.setDefaultGatewayUrl


Property Detail

version

static  version: String  

Component version. For internal use only.

Comments


No screen name said on Jan 26, 2005 at 2:41 PM :
if NetServices.getHostUrl() is deprecated now... is there any other way to sniff our the URL the SWF is embedded in aside from NetServices.getHostUrl()?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flashremoting/mx2004/actionscript_api_reference/mx/remoting/NetServices.html