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:
[OperationContract]
float AddFloat(float a, float b);

[OperationContract]
MathResult Add(MathParameters parameters);

[MessageContract]
public class MathParameters
{
    [MessageBodyMember]
    public double a { get; set; }
    [MessageBodyMember]
    public double b { get; set; }
}

[MessageContract]
public class MathResult
{
    [MessageBodyMember]
    public double Result { get; set; }
}


Result values are a little different. Return values using simple return values are unnamed:
re.result[0]
Return values from MessageContracts are strongly named:
re.result.Result

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

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

Comments

No comments yet.