Cairngorm and Flex Builder’s magical WSDL tool
So, I’m working with a client doing some development and mentoring. A piece of this is implementing the Cairngorm micro-architecture and mentoring duties surrounding this. The client’s developers made full use of the new WSDL import tool in Flex Builder 3 and are really sold on using it. Now, for those not paying attention here, the title did mention Flex Builder’s magical WSDL tool, Flex builder 3 has this really neato, down-and-dirty, quick-and-easy WSDL tool. Look under the Data menu item and choose Import Web Service(WSDL). You’ll get a little wizard GUI where you pick the project and source folder to put the code in, enter a WSDL location, choose what methods in the WSDL you want to include in the magical WSDL import tour, mash a button, and sit back and enjoy. After its done, take a look at the code generated…holy FSCK Batman!!!! Yeah, a whole butt load of code is generated. Totally bad ass, eh? Unfortunately its all generated in one folder, VOs, Events, service, etc. But hey, you can’t have it all in a badd ass world! So, how to use it?
You should see a file called something like
var myService:MyAdmin= new MyAdmin();
myService.addGetSessionEventListener(myResultHandlingFunction);
myService.GetSession(myUserName,myPassword);
where GetSession() is a method in my WSDL. That’s it! Uber kewl eh?
So, in just a few seconds your complete Service layer is written. To add more icing to this cake, all the service calls return TYPED OBJECTS FOR YOU! The type is based on your WSDL scheme. Thus you literally need only bolt on your UI and voila, impress your boss.
The downside: as this code is generated and we live in such a API imperfect world, you may have to regenerate it from time to time when your WSDL changes. So, you can’t really modify the code without worrying about maintaining it. Sure, in some cases you can play extend the class, but not always as some things are private Private! Like most magical gen tools, in my experience, they are always a canned solution. Meaning, they are designed to do one thing, not all the things your client may want. In this case though, things seem pretty cool as its the Service layer after all.
But wait! There’s more? Does it chop and shred lettuce too? ha, afraid not, but there is more. Most likely you will be using a framework in your app and most likely it will be Cairngorm, eh? I know, a bit jaded. So, how to tie in this code to Cairngorm use? Use the Delegate baby! In the generated code, find a file named Base
var service:BaseMyAdmin = new BaseMyAdmin();
var token:AsychToken = service.getSession(username, password);
prepareResponder( token, resultHandler, faultHandler);
you that’s it folks. I’m willing to bet the other frameworks out there PureMVC, ARP, Mate, etc… all work with tokens at this level, so should be just as easy.
To recap, we have a quick and easy way to work with webservices and your favorite framework with two major gains:
- Typed Objects from WSDL calls
- Time Savings
Others may see more benefits, but these are key to me, #1 especially as I don’t have to manually parse through XML creating typed objects.
back to coding!
peas
DK




