Current location: Brighton, UK

Cairngorm and AMF:PHP - bending Services to work with NetConnection

Posted on Thursday, March 06, 2008 @ 16:22 CET

At work I've been getting into Cairngorm for a little while now and its quite a beast to tackle. It took me three attempts to actually grok what was going on, and although the article on DevNet is great and the examples I found are good (the image helps) until you actually play with it you might be as lost as I was.

The biggest problem was setting up the business services. The Cairngorm Store example uses <mx:RemoteObject /> tags that tie in to the ServiceLocator. However, those have to be defined in services-config.xml and the endpoints are hard-coded and baked in (unless you do some Ant magic). That's something I didn't want to do, and also I'm using NetConnection to talk to AMFPHP.

So what I ended up doing was rolling out a business Services class as a Singleton class (instead of an MXML) with a single NetConnection object, instead of one per service. I don't think this matters since every business Delegate has to know the remote method name anyway and I find its better to keep all that stuff within the Delegate. That way the Services class knows about the endpoint and encoding type, and the Delegates know what they're calling.

The second change is within the Delegates. Instead of defining service as an Object, I define it as a NetConnection object. Also, the Delegate constructor receives an IResponder object to use as a responder. The problem is this is a mx.rpc.IResponder object, and NetConnection only plays with flash.net.Responders. However, they are pretty much identical so instead of doing like so:

public function getProducts() : void {
     var call : Object = service.getProducts();
     call.addResponder( responder );
}

I do like so, simply creating references to the IResponder object's methods:

public function getProducts():void {
     var r:Responder = new Responder(responder.result, responder.fault);
     // service is a reference to the connection within the Services class
     service.call("getProducts", r);
}

So the main concepts and ideas behind Cairngorm remain intact (I believe). I'm still a n00b when it comes to the microarchitecture so there might be something I missed, but this is working great for me for now :)

- paulo

Post a comment:

You must have Flash and JavaScript enabled to post a comment.