The First and Only Magazine for Macromedia MX™
   
 
Notes from the Flash, Flex and ColdFusion trenches

Category List

Quick Poll

Where are you located?
North America
South America
Europe
Asia
Africa
Australia

My RSS Feeds








Hit Counter

Total: 1,350,997
since: 20 Jan 2005

Search Box

 

Search The Web

Google

MAX 2008

Fun Stuff

Mailing List

Got A Question?

Got A Question?

Leave a comment by the appropriate Entry, or email me

Tag Cloud

                                                                                                                       

Calling a WebService Purely through AS

posted Tuesday, 30 August 2005

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 {
          super.init();
          remoteDataService = new mx.servicetags.Service(this._url, "http://localhost:8500/mmcourses/faad2004/dbs/Bikeparts.cfc?wsdl", new mx.services.Log(1, "WebService"), null, this, null, null, null, null, false);
           remoteDataService.__name = "remoteDataService";
           remoteDataService.__faultHandler = function(event) {
               faultHandler(event)
           }
           remoteDataService.__resultHandler = function(event){
                resultHandler(event)
          }
          remoteDataService.__showBusyCursor = true;
      }
      // event handlers
      private function faultHandler(event){
          mx.controls.Alert.show(event.faultstring);
     }
     private function resultHandler(event){
           mx.controls.Alert.show(event.result.length + " results received");
      }
      // public API
     public function makeCall(method:String){
          remoteDataService[method]();
     }




}
This can be instantiated in MXML like this:



<mx:Application
 xmlns:mx="http://www.macromedia.com/2003/mxml"
 xmlns:c="*" creationComplete="dm.makeCall('getProdTypes')">
 <c:ASWebService id="dm"/>
 
</mx:Application>



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.

tags:  

links: digg this    del.icio.us    technorati    reddit




1. veejay left...
Tuesday, 25 October 2005 4:55 pm

Hi,

  • Can you let me know how this is possible now using FlexBuilder2?

thanks


2. Jeff Tapper left...
Sunday, 4 December 2005 5:44 pm

Veejay - take a look at my AS3 DataManager post -- http://jeff.mxdj.com/as3_datamanager.htm


3. TimHoff left...
Sunday, 26 February 2006 1:52 pm

Is there a way to showBusyCursor through AS is your example?


4. deepak left...
Thursday, 23 March 2006 2:26 am

What will be the syntax for create a RemoteObject instance. Thanks