2007-11-15

Web Services in Flash 9 - AS3

While the push from AS2 to AS3 was completely brilliant and Flex2 and Flex3 are absolute heaven for an OOP programmer, Flash CS3 in AS3 is turning out to be a major dissapointment. All the enhancements and improvements in Flex are met by equal and opposite cuts in Flash functionality.

WebServices: Gone
Remoting: Gone
Binding: Gone (well... Binding was introduced in CS3... but only in AS2)

The upside though is that the developer community is strong enough to compensate these blemmishes on the otherwise beutiful face of Flash.

While looking for a WebService package, I stumbled upon Carlo Alducente's brilliant WSDL parser and service wrapper (http://labs.alducente.com/?p=7). The only problem is the error handling... and in order to handle errors nicely, what you really want is an AsyncToken... and a Fault class... and a FaultEvent... And a ResultEvent...etc.

So I rewrote the service package. Although it is packaged as se.manmachine.rpc, all the WSDL parsing and WebService method registering is the work of Carlo. I still haven't recieved his permisson to use his code in this way. Hopefully I will. Kudos Carlo!

The future plans is to extend the package to incorporate RemotingService (RS and WS both extending AbstractService), and using the Proxy class for registering dynamic methods... And then of course adding events for Invoking and headers, wrapping the headers... well... pretty much implementing the whole mx.rpc package for Flash. The future, however, lies in the future.

Download

13 comments:

Anonymous said...

Hey Johan!

I've actually been thinking about the most glamorous way of implementing some sort of error detection without it getting too complicated for the user.

I'm very glad that you wrote your own package for it and I'm very excited to see what you came up with. You have my permission to add to the package and I hope you make tweaks and changes to make the project even better.

Please keep me updated! I'll add you to the blogroll! Thanks!

Anonymous said...

One more thing, can you provide an example of how to use the error event handler? That would be awesome! Thanks again!

Johan Öbrink said...

Glad you like it :)

I corrected some bugs and wrote a code example as a new blog post.

Unknown said...

Johan,

Before you put any more time into this. I think you should take a peek at my solution for using the Flex RPC classes directly into flash.

Check out my post:
http://labs.qi-ideas.com/2007/12/25/using-flex-compiled-code-within-flash

hinkle said...

I tried to use this lib for a non-asmx web service and it didn't work, it wasn't able to parse the methods properly.

The wsdl I tried was the default one provided with the Apache Axis2 project.

Anonymous said...

Could you provide an example of how to create callback functions with this package?

Thanks,

Anonymous said...

Hi,
Thanks for the information.
But how can I use Username/Password with this code?
Help would be appreciated.
Thanks

Felipe said...

Does this solution work with RPC-style services?

Anonymous said...

It's a great class except you didn't make it so that it could send XML, it just recieves it. Most services communicate through xml not arrays. Any chance of updating that and reposting?

Anonymous said...

Thanks for your work on this - Im trying to get it working using a .svc?wsdl instead of .asmx?wsdl and I cant get it working. Does anyone know what the difference is or how I might get it to work? the error returned is '(webServiceMethodName) is not a function' - ie it cant seem to call any of the methods in the webservice. Ideas?

Greg said...

Hi, thanks Johan, this was extremely useful.
I found a bug in the method call queuing when you call a service in quick succession. In fact I'm not sure why the WSProxy is a singleton with a queue at all? If you create a new WSProxy for every method invocation and get rid of the _callQueue and _busyOnCall code, you can just multiple service calls asynchronously...

Japan used heavy machinery supplier said...

Hi, Thanks for this information. I read this coding and I think it's good effort.I'll implement this.

Anonymous said...

Hi alducente ,
Gr8 work.
I am having a problem calling .svc webservice from your code. i.e. WCF service