SOAP is Just XML

Recently, Branden and I were tasked to build a Flash UI on top of a web service.  Seems like pretty standard development...but, as you have to know by now, nothing is ever "standard" at Automata.  After some research, trial & error, and hand-wringing, we realized that the device we were attempting to connect to was using SOAP 1.2.  Well, unfortunately, Flex only supports up to SOAP 1.1, so we had a bit of a problem.

It didn't take us long to remember that SOAP was just XML, and that Flex's web service API was just a nice class that makes it easy to speak that language.  After deciding to nix the Flex solution (we were only using Flex for the WebService API), we moved to an all Flash solution.  We created a connector class to act as a web service API, and simply sent XML packets directly to the server using URLLoader.  One note about this solution is that it will only work if you have knowledge of the web service you are trying to use.  In our case, we had the entire schema at our disposal, so we knew the exact format of the service operations.

The connector class contains public methods to call the individual web service operations.  Additionally, we created individual request classes for each of the operations that extended a class called Abstract Request.  AbstractRequest provides a method send(uri:String, headers:Array) that uses URLLoader to send the request to the server.

The "uri" parameter of send() is the full path to the web service, with the "http://" attached.  The headers are the HTTP headers that you need to send to the web service for such things as authentication.  In our code, these are set in the Connector class, and passed to each request as it is needed.  The "_request" property holds the XML object that you will pass to the server.  This XML is formatted as an XML packet specific for this web service.  The value for this property is defined in the AbstractRequest sub-classes.

The _request property is an XML object that defines the format, and uses Flex-style binding to add the actual data from the constructor parameters.  This is a little-known XML trick you can do in AS3.  Branden found it in the Help section of the Flash CS3 IDE.  Pretty neat if you ask me.

Back to the AbstractRequest class, we simply set the data property of the URLRequest intstance to be the string representaton of the request XML, and call URLLoader.load(), passing in the URLRequest instance.  This sends the XML packet to the server.  The handler for Event.COMPLETE will receive the XML returned from the server.

Our connector class has methods like:

public function addGroup(groupId:String, groupName:String, flag:String):void {

var request:AddGroupRequest = new AddGroupRequest(groupId, groupName, flag);

request.addEventListener(ISYResultEvent.EVENT, onResult);

request.addEventListener(ISYFaultEvent.EVENT, onFault);

request.send(_uri, _headers);

}

This actually executes the web service call.

And just like that, you've build your own web service class.  While it's quite specific to the web service you are using, you could certainly expand it to consume a WSDL file so you can use it for any web service.

Chanel - Fragrance & Beauty

Last StudyNext Study

How do you build a massive site for one of the world’s most prestigious and elegant brands that handles a dozen different languages with individual character sets, creates content through an intuitive CMS, maintain efficient loading times without putting strain on your server and is account for future development of new rich media content? Hire Automata Studios.

For their recent worldwide site rollout for the Fragrance & Beauty division, Chanel partnered with us to develop a smart and effective way to handle their multi-lingual needs. Layouts that render on the fly based upon a user chosen language, parallel development of a comprehensive CMS and front end user interface, and the creation of a custom API for future content and application development were just a few of the many challenges we were hired upon to tackle.

Working as the technical developer and liaison between Chanel’s in-house international design team and a backend database department, we found new and innovative ways to approach their specific needs. Our solutions allow scalability and adaptability without sacrificing efficiency or loading times. Custom created UI elements and CMS work with our API to allow Chanel’s site to grow as their needs change, from season to season, year after year.