You will need the Flash Remoting MX Components installed and added to your classpath in order to be able to use AS2 Flash Remoting.

Add references to the appropriate libraries:
import mx.remoting.*;
import mx.remoting.debug.*;
import mx.rpc.*;

Write handling events:
function handleResult(re:ResultEvent) {
	trace("Got result of type "+typeof (re.result));
function handleFault(fe:FaultEvent) {
	trace("Fault: " + fe.fault.faultcode + ", " + fe.fault.faultstring);

Create your endpoint:
var svc:Service = new Service("http://localhost/Example6.svc/amf");

Once your setup is complete, making calls are relatively simple:
var pc:PendingCall = svc.Add(1, 2);
pc.responder = new RelayResponder(this, 'handleResult', 'handleFault');

Each argument to the actual method call gets treated as a separate "body part" - it works the same whether using MessageContracts or not. The above call can use eiter of the following declarations:
float AddFloat(float a, float b);

MathResult Add(MathParameters parameters);

public class MathParameters
    public double a { get; set; }
    public double b { get; set; }

public class MathResult
    public double Result { get; set; }

Result values are a little different. Return values using simple return values are unnamed:
Return values from MessageContracts are strongly named:

Make sure you know which you need before writing your code!

Last edited Oct 20, 2009 at 10:03 PM by mdekrey, version 1


No comments yet.