Home > AS3 > Web Service in AS3, Release 1.0

Web Service in AS3, Release 1.0

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.

Click here to download the package!

Categories: AS3 Tags:
  1. gmalta
    October 29th, 2007 at 13:15 | #1

    Hi,

    first of all great work, but i have oen question , those it suport https request ?

  2. gmalta
    October 29th, 2007 at 13:37 | #2

    * does it support https ?

  3. October 29th, 2007 at 13:45 | #3

    Thanks gmalta, as for your https question I’m not totally sure, I built the class so I could use it for regular services built using ASP.NET (what I usually use), which I believe uses regular http. This class has not been fully tested with anything else which is why I posted it for others to use, so I know what it can and can’t do. I can’t imagine why it wouldn’t work over https, but it is an interesting question, I’ll have to look further into that. I’ll let you know if I find anything.

  4. October 29th, 2007 at 14:28 | #4

    After consulting Mark AuCoin (www.clevermongrel.com), a back-end developer, who explained to me how sending requests using https works, the answer to your question is no. Unfortunately, this class was designed for regular queries. But it’s something that I will keep in mind for the next version. Thanks for bringing that topic up, gmalta.

  5. gmalta
    October 29th, 2007 at 15:36 | #5

    HI alducente,

    thanks 4 the quick reply, i´m really enjoying your class for a little demo (widget ) i´m doing , i will have to skip the autentication part.

    Keep up the good work.

    Gmalta

  6. Martin
    October 31st, 2007 at 08:40 | #6

    Brilliant AS3 extension, unfortunately I also need the HTTPS feature to use this for all my projects. I will be looking forward to the next version :-)

    Keep up the good work.

    Martin.

  7. October 31st, 2007 at 10:53 | #7

    Thanks! thanks for your package.. works perfect with ASP.net!

  8. November 8th, 2007 at 11:22 | #8

    Hi!
    Your classes are really extremely useful us!!!
    I’ve tried to use it with our java based server. Our WSDL documents are generated by X-Fire. While parsing this document there were no availble Web Service methods got:( I took a look throw your sources and it seems to be a bug in WSDL.as class. In method getBinding() there were no bindings found while parsing wsdl document. In your code service.wsdl::port.@name is compared with portType. Is it really right? I’ve modified this method in the next way:

    private function getBinding(portType:String):String{
    var wsdl:Namespace = __rawWSDL.namespace();
    var service:XMLList = __rawWSDL.wsdl::service;
    // var myPort:XMLList = service.wsdl::port.(@name == portType);
    var binding:XMLList = __rawWSDL.wsdl::binding.(@type.substr(@type.indexOf(":")+1) == portType);
    var addressNS:Namespace = service.wsdl::port.children()[0].namespace();
    __servicePath = service.wsdl::port.addressNS::address.@location;

    var bindingAmount:Number = binding.length();
    if(bindingAmount == 1){
    return (binding.@name);
    } else if(bindingAmount >0 ) {
    return binding[0].@name;
    }
    return("");
    }

    Now it seems to be work properly. I’ve test my changes with our X-fire generated WSDL documents,
    http://ws.cdyne.com/ip2geo/ip2geo.asmx?WSDL document
    and http://mail.yahooapis.com/ws/mail/v1.1/wsdl document.
    In all this cases modificatitons works propertly :)

    Probably this will be useful for you:)

    Thanks one more time for your code!!!

    Best regards,
    Vladimir

  9. November 8th, 2007 at 16:17 | #9

    Great work Vladimir! Thank you so much for your contribution!

    Again, I have only used this class with web services created in ASP.NET and had no idea how to test for other types of services as I don’t have access to them. I will add your code and give it a couple test runs, if all goes well I will release the next package with it.

    Now that it’s been brought up, if anyone else has any issues with using this class please leave a comment, I’m more than happy to do my part on research.

  10. John
    November 8th, 2007 at 19:31 | #10

    Thanks for your hard work implementing a Web Services class for AS3. It will come in handy for many of us.

  11. November 15th, 2007 at 07:56 | #11

    Great work on the WebServices. I really liked the WSDL parsing. I wasn’t to crazy about the calling methods though. Passing a complete function to each method and hoping it doesn’t fail just isn’t the way I want to do it…

    So I took the liberty of rewriting it.

    http://manmachine-tech.blogspot.com/2007/11/web-services-in-flash-9-as3.html

  12. FST
    May 6th, 2008 at 18:31 | #12

    Great work on the Service. I was wondering if you have any intention of incorporating SOAP:FAULT support? I’m currently getting the following when I run across a SOAP:FAULT:

    Error #2032: Stream Error. URL: [SERVICEURL]

    Thanks!

  13. Pierce
    June 6th, 2008 at 12:06 | #13

    Thanks for your work! One question/(potential) bug: when I initially load up my SWF, I call the service a number of times to load up different data. I found that in some circumstances, a call would get made and fall through the cracks. Specifically, the __busyOnCall flag in WSProxy would be false, though there were calls to be made in the queue. I corrected this by changing the check in the callMethod() function to if (!__busyOnCall && __callQueue.length == 0) {
    // etc…

    I was wondering if you’d seen this behavior elsewhere and if so how you corrected it.

  14. Jonson
    June 10th, 2008 at 21:34 | #14

    Hi everyone, I have downloaded the webservice 1.1.zip, Bought Adobe Flash Cs3 Professional But found out AS3 does not have web services. But, what to do with the downloaded files? i need some detailed help here. Would appreciate the help very much.

  15. Brandon Luhring
    June 12th, 2008 at 13:37 | #15

    Flash Player Version Alert!

    We had used this terrific class in a site earlier this year. We started to hear complaints that the service would just sit and spin and never do anything. However we couldn’t recreate the issue….until recently.

    There were security changes in Flash Player versions sometime around version 9.0.120.0, so versions prior to that (like 9.0.42.0) worked fine, versions after that (like 9.0.124.0) fail.

    The solution is to add a new item to the crossdomain.xml file, that looks like this:

    Previously all we had in the crossdomain.xml was this:

    We’ll also be looking into the extension of this class by Johan Obrink at the Man Machine Tech blog, where he’s adding error/fault checking, so future changes to Flash can be caught instead of leaving the visitor hanging. I see Carlo and Johan have chatted over on that blog.

    Thanks again for the great work!

  16. Dan Doyle
    July 7th, 2008 at 05:28 | #16

    Hi, great work on this but I am having a bit of trouble with a returned XML request. In the returned XML all of the tags are replaced with < > tags respectively – I have spoken with some of the other guys working on this and they do not think that it is an encoding issue, has anyone ever come across this before?

  17. July 7th, 2008 at 07:05 | #17

    @Dan–

    I have never encountered this problem before, but one quick way is to just replace the characters once it’s loaded. Take a look at this blog and let me know if it helps:

    http://www.razorberry.com/blog/archives/2007/11/02/converting-html-entities-in-as3/

  18. Dan Doyle
    July 7th, 2008 at 10:39 | #18

    That worked a treat – thanks

    Just read my comment again and realised that it converted the html encoding – d’oh! Probably should have read that sooner :-)

    Thanks again for your help

  19. July 7th, 2008 at 11:04 | #19

    Good to know that worked, kudos to Brandon ( http://www.headwindslab.net ) for providing me with that link.

  20. Jonson
    July 8th, 2008 at 01:51 | #20

    Hey, i downloaded teh webservice gofr 1.1 and how do i parse teh soap response? What sending action should i add at WsMethod.as? i am really confused, please contact me through my email.THanks! Email jonson_koh@hotmail.com

  1. January 8th, 2008 at 19:52 | #1