Navigation:  Client Support > AIR > Remoting >

AIR and Java with HTTP/AMF

Previous pageReturn to chapter overviewNext page

Since AIR client is not loaded from a web server, it is important that the destinations it uses are associated with an absolute endpoint URL. Follow the steps below to enable AIR client to communicate with WebORB via HTTP/AMF:

1.Locate and open in a text editor services-config.xml from the WEB-INF/flex directory from your WebORB installation.
2.Add the following channel definition to the file:

<channel-definition id="air-http" class="mx.messaging.channels.AMFChannel">
  <endpoint uri="http://localhost:8080/weborb.wo" class="flex.messaging.endpoints.AMFEndpoint"/>
  <properties>
    <polling-enabled>false</polling-enabled>
  </properties>
</channel-definition>

3.Notice the "uri" attribute in the "endpoint" element. The value specified in the attribute is the URL where WebORB process incoming remoting requests. You can verify the URL by opening it in a web browser - WebORB should open the management console if it is properly configured. It is also important to note that the host name in the URL must be reachable by the AIR clients. The value of localhost is applicable only when the AIR client and WebORB run on the same computer.
4.Locate and open in a text editor remoting-config.xml from the WEB-INF/flex directory.
5.Add the following destination definition:

<destination channels="air-http" id="GenericAIRDestination">
 <channels>
   <channel ref="air-http" />
 </channels>  
 <properties>
   <source>*</source>
 </properties>
</destination>

6.Notice the destination uses the air-http channel defined in step 2. As a result, all remoting invocations sent to the GenericAIRDestination destination will be sent over the endpoint URI associated with the air-http channel.
7.Open project properties In Flex/Flash Builder and select Flex Compiler. Add the following additional compiler argument:

-services "c:\[PATH-TO-YOUR-WEBORB-WEBAPP-OR-WEBORB-ENABLED-APP]\WEB-INF\flex\services-config.xml"

The client's application code should use the GenericAIRDestination destination as shown below.

import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
 
public var remoteObject:RemoteObject;
 
public function init():void
{
 remoteObject = new RemoteObject( "GenericAIRDestination" );
 
 // identify the name of the .NET class (or WCF service, Spring.NET bean, etc)
 remoteObject.source = "com.foo.MyService";
 
 // add listeners for the result and fault events for the methods in
 // your .NET service - using "myMethod" as an example here:
 remoteObject.myMethod.addEventListener( ResultEvent.RESULT, gotResult );
 remoteObject.myMethod.addEventListener( FaultEvent.FAULT, gotError );
 
 // invoke your method
 remoteObject.myMethod();
}
 
public function gotResult( evt:ResultEvent ):void
{
}
 
public function gotError( evt:FaultEvent ):void
{
 Alert.show( "server reported an error - " + evt.fault.faultString );
}