Calling a WebService Purely through AS

On the flex coders list, folks often ask if its possible to call a WebService purely with ActionScript.  Its been asked so often, there is even an entry in the FAQ about it.  According to the official word from Macromedia, there is no supported mean to create a WebService purely through ActionScript,  however, it is actually possible, just not supported.  My standard disclaimer (see TabNavigator article) about using unsupported code applies.

Actually, its not really that hard to do.  A simple class to instantiate a WebService looks like this:

class ASWebService extends mx.core.UIObject{
    private var remoteDataService:mx.servicetags.Service;

      private function init():Void {
          remoteDataService = new mx.servicetags.Service(this._url, "http://localhost:8500/mmcourses/faad2004/dbs/Bikeparts.cfc?wsdl", new, "WebService"), null, this, null, null, null, null, false);
           remoteDataService.__name = "remoteDataService";
           remoteDataService.__faultHandler = function(event) {
           remoteDataService.__resultHandler = function(event){
          remoteDataService.__showBusyCursor = true;
      // event handlers
      private function faultHandler(event){
     private function resultHandler(event){
  + " results received");
      // public API
     public function makeCall(method:String){

This can be instantiated in MXML like this:

 xmlns:c="*" creationComplete="dm.makeCall('getProdTypes')">
 <c:ASWebService id="dm"/>

Word on the street is there will likely be a supported way to do this in Flex 2.0, but like talk about any unreleased product, at this point it is no more than a rumor.

I’ve put together a supported way to do this in Flex 2.0, which you can read about in my AS3 DataManager post.

There are no comments.

Leave a Reply