gofr: AS3 Web Service

Introduction

gofr is the new project name for my AS3 web service package. I figured “AS3 Web Service” was a little lengthy, and using code names are really cool. ;)
This will be the new home for this package. You will be able to read up on any updates or new downloads.

Features

  • 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.
  • Optional Caching: Saves responses for faster access.

Releases

  • [11.14.07] gofr 1.1 – Click To Download
    - Added optional caching feature
    - Added support for Java based servers using X-Fire

Usage

Simple web service calls

//Required imports
import alducente.services.WebService;
import flash.events.*;
//Instantiate the class
var ws:WebService = new WebService();
//Add a listener for when the web service methods become available
ws.addEventListener(Event.CONNECT, connected);

//Connect to the service by downloading the WSDL
ws.connect("http://ws.cdyne.com/ip2geo/ip2geo.asmx?WSDL");

//Once connected, call an available method on the service named "ResolveIP" with the appropriate parameters
function connected(evt:Event):void{
	ws.ResolveIP(done, "192.123.0.200", 0);
}

//This function is called when there is a response from the sesrvice
function done(serviceResponse:XML):void{
	trace("nWeb Service Result: ");
	trace(serviceResponse);
}
  1. December 5th, 2007 at 23:31 | #1

    super Cooool!

  2. Johan
    December 18th, 2007 at 07:52 | #2

    Cool! It worked on the first try :)

  3. December 20th, 2007 at 18:08 | #3

    Any sample .net code or tips I could give my .net guy. He is lost.

    Thanks!!

  4. December 20th, 2007 at 20:44 | #4

    Craig, If you can provide me with the WSDL you’re working with, I might be able to help you.

  5. December 28th, 2007 at 11:25 | #5

    This rocks so much butt, picking up Adobe’s slack, you deserve some butta on your toast, cheers.

  6. January 17th, 2008 at 14:08 | #6

    Carlo
    Thanks for your response. We are making headway and have had no problems with your class. I am trying to do a try/catch around the web service connect but can’t seem to catch the error. Any suggestions would be appreciated.
    And again, thanks.

  7. January 20th, 2008 at 11:28 | #7

    brilliant! i went through it this morning –no problems except you you should add those Usage comments to the sample fla — I created a very simple web service in Visual Studio with a HelloWorld method — connected to it but I was scratching my head about how to make a method call once I got back my method list, and had to return to your blog to re-read the usage example — eureka:

    function connected(e:Event):void
    {
    ws.HelloWorld(done);
    }

    this will be a great help in our next project…

  8. January 31st, 2008 at 22:40 | #8

    Thanks for sharing

  9. January 31st, 2008 at 22:49 | #9

    you kick so much ass it is not funny!

  10. Vaderist
    December 8th, 2008 at 16:41 | #10

    This class is working great for me when I attempt to access the web service from within the flash player. However, once I upload it I am unable to access any methods located in the wdsl. I can access the wdsl, but then when I attempt to call a method contained therein, it hangs. Any thoughts?

  11. Vaderist
    December 8th, 2008 at 17:56 | #11

    I found the problem. My DB guy returns the XML data without any SOAP formatting. What I needed to do was comment out these lines in WSProxy.as

    var soapAction:URLRequestHeader = new URLRequestHeader(”SOAPAction”, action);
    urlRequest.requestHeaders.push(soapAction);

    All is working great now! It took me a while to get this to work but I learned a lot along the way. This is a well-crafted script… Just wish it was documented better.

    Thanks!

  12. December 8th, 2008 at 18:07 | #12

    @Vaderist

    Do you have a crossdomain.xml up on the root of your server? If you are accessing the service from a different server than where the service is, or if you are connecting with an absolute url, you need to allow access by using a crossdomain policy file.

  13. Lee
    December 30th, 2008 at 01:52 | #13

    Hello,

    I’m new with all this SOAP stuff, so please excuse me if the answer to this is obvious. I am trying to connect to a .NET Web Service. I used soapUI to see what it was expecting. This is what it gave me:

    ?

    Now, when I use your class, how do I tell it to assign the data to ‘gameId’?

    I tried something like ws.StartGame(”XXXXXX”), but it returns the error: Error #2032: Stream Error.

    take care,
    lee

  14. Lee
    December 30th, 2008 at 01:54 | #14

    oops….I meant I make the call ws.StartGame(ok, “XXXXXX”)..

    also I just noticed in my last message all the SOAP code disappeared. It was just a listing about StartGame telling that it needed a variable called ‘gameId’.

  15. NielsR
    March 6th, 2009 at 10:32 | #15

    First of all, your classes have been very useful to me.

    Right now, I have a problem using a Date variable in the service call. The web service is not publicly available yet but it looks something like this:

    public var birthDate:Date = new Date(1970,07,01);

    and the call goes something like this:

    ws.Calculate(done,5000,100,birthDate,10);

    In the old as2 webServiceConnector component the same call to the same URL works fine but I get the feeling that these classes don’t support the Date variable in as3. Is this true? I get the #2032 error when trying.

  16. ozgur uksal
    August 19th, 2009 at 23:03 | #16

    appreciatde for the webservice class. have a question. What is the suggested approach to free the memory once you are done with the webservice? Is it fine to do just ws.removeEventListener( Event.CONNECT, connected);
    ws = null

  17. August 20th, 2009 at 16:11 | #17

    Thankyou, thankyou,thankyou!
    The class works fantastic, just as reported!

    However, I’m having a bit of a problem with accessing webservices on a Mac projector – can anyone please help?

  18. August 25th, 2009 at 16:33 | #18

    @ozgur uksal – Like all other objects the best way to free it is to remove all the listeners and any references to it, the garbage collector should do its thing.

    @Dale – Your issue could be any number of things, one thing I’ll suggest is to make sure your firewall (if you have one running) isn’t blocking any connections from your desktop to the net.

  19. Ben
    September 11th, 2009 at 15:48 | #19

    I’d like to pass an object to my .Net WebService. The object is serializable in .NET, but I can’t figure out what I need to do with ActionScript 3 to pass this object.

    I tried: myWebService.ServiceMethod(done, {FirstName:”Foo”,LastName:”Bar”});

    … but it bombs everytime. What gives?

  20. September 16th, 2009 at 17:12 | #20

    Hey Ben,

    The reason it “bombs” every time in your case is because these classes only handle simple data types, I wrote these to handle simple communication with a .NET service because that’s all I really needed it to do at the time. I posted it to provide a starting point for anyone who might be interested in taking it apart and improving it, like what many others have done.

    So in short, complex data types == bad. There’s plenty other alternatives now that as3’s been around for a while, google is your friend.

  21. Lyn
    September 25th, 2009 at 16:45 | #21

    YAY!!!
    You’ve saved me sooooooooo much time and #@#$!
    <3

  22. October 2nd, 2009 at 18:32 | #22

    adulcente,

    What can I do to implement error handling around my web service methods. I am running into unhandled web service exceptions in a production environment. They aren’t caused by this library, but I need a way to trap them and continue.

    I do my web service calls at timed intervals while the application is running. But it seems that when the error hits, my web service calls no longer execute, even though setInterval continues to execute and the cause for the error has been corrected on the server side.

    Thanks in advance!

  23. November 4th, 2009 at 07:05 | #23

    Hello Carlo, many thanks for this very handy package. You saved me a lot of work and time!

  24. November 10th, 2009 at 11:33 | #24

    Hi,
    just wanted to say that it looks like your lib saved my butt today. I usually do Flex, and naively assumed that I could do webservices in Flash too. It was looking nasty, but I found your lib
    thanks! (yeah it’s for last week)
    Ariel

  25. November 18th, 2009 at 02:11 | #25

    Anyone have an issue with this on a hosted environment?
    I have no problems with consuming the webservice on my local machines and network but when placed onto a hosted box, it just hangs on the call?

    Awesome work! now if I can just get it to work!

  26. November 18th, 2009 at 17:58 | #26

    @Frank
    crossdomain issue! ignore this one! Great work!

  27. November 19th, 2009 at 19:02 | #27

    Hello,
    Fantastic fix, wondering how to bind it to a Data Grid in as3. my test of your code returns XML but the first part is cut off, no SOAP data…

  28. vini
    November 20th, 2009 at 05:46 | #28

    how to fix this crossdomain issue! i placed crossdomain.xml on the server root with “*” and also given Security.allowDomain(”*”) in flash but still i am not able to connect the wsdl

  29. Andrew
    December 1st, 2009 at 23:06 | #29

    Hi, what if my web services is over HTTPS.. I have tried the class but unavailble to connect. Any work around solution?

  30. Jonas
    December 3rd, 2009 at 11:51 | #30

    Is there not any IO error handling in this package? Seems like a pretty standard implementation or am I missing some event?

  31. JOeri
    December 4th, 2009 at 13:31 | #31

    I have exactly the same question / problem as Noah Lively. I’m using timed calls to a webservice.
    When I call a method on the webservice, before my previous call is being finished, it fails every call after. Is there a way to “flush” the calls I am pending or something?

    Thanks!

    Joeri

  32. December 7th, 2009 at 15:14 | #32

    Hey everyone,

    To be completely honest, I’ve stopped updating these classes and the main reason behind posting this for everyone is so that you guys can take it apart and use it as a base for your specific needs. I’ve also been approving comments in hopes that your questions can be answered by someone else.

    So just to get things out of the way:
    - No HTTPS support, something I meant to do but never had time to.
    - No Error handling, again, something I never had time to do. But please take a look at what Johan has done to my classes to see if it’s something you can use: http://manmachine-tech.blogspot.com/
    - Please remember to enable SOAP requests in your crossdomain.xml files

    Thanks for the support but I’m afraid I have very little time to spend on these classes as I’ve been diving into more webcam/flash integration. As of today, there are many other libraries out there that might suit your needs better. In fact, I think I read about someone packaging up the flex classes for use in flash.

    Thanks guys,
    - Carlo

  33. Ken
    December 18th, 2009 at 18:54 | #33

    Fantastic – works perfectly. Thanks Carlo.

  34. Casper
    December 22nd, 2009 at 04:42 | #34

    Hi Guys

    I am new to AS3 and I am having trouble to connect to the WSDL. I get a Security error once i try to access the WS. The error is “Untrusted local SWFs may not contact the Internet.” I have changed the settings to always allow access but still it does not go away.

    Do i need to run the SWF file from within a webpage or will the projector.exe file still work?

    Thanks in advance.
    Casper

  1. November 14th, 2007 at 17:08 | #1
  2. November 14th, 2007 at 17:10 | #2
  3. November 14th, 2007 at 17:15 | #3
  4. February 2nd, 2008 at 11:47 | #4
  5. July 7th, 2008 at 10:41 | #5