Web Service in AS3, Release 1.0
October 27th, 2007
20 comments
I completed what seems like a stable version of my web service class. It’s been tested on 3 different services and has been successful in calling methods in each of those 3 services. Some features in this class are:
- Queued service calls: Methods will be executed in the order they are called in.
- Assign callbacks: You can assign a function to execute for every service call you make when the response has loaded.
- Automatic SOAP requests: The class will build and send the SOAP requests for you, no need to create chunks of XML manually.
Here’s come example code using a sample webservice taken from “Advanced ActionScript 3 with Design Patterns” book:
import alducente.services.WebService;
import flash.events.*;
var ws:WebService = new WebService();
ws.addEventListener(Event.CONNECT, connected);
ws.connect("http://ws.cdyne.com/ip2geo/ip2geo.asmx?WSDL");
function connected(evt:Event):void{
ws.ResolveIP(done, "192.168.0.125", 0);
}
function done(serviceRespone:XML):void{
trace("Web Service Result: ");
trace(serviceRespone);
}
Being able to call web service methods easily was the first thing on my mind while building this object. As you can see above, all you need to do is call a method in the object which would have the same name as the method you are trying to call in the web service. The first parameter would be the function you want called when the response is loaded and everything else are the parameters that method is expecting.
Categories: AS3