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.
Categories: AS3
Hi,
first of all great work, but i have oen question , those it suport https request ?
* does it support https ?
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.
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.
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
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.
Thanks! thanks for your package.. works perfect with ASP.net!
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
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.
Thanks for your hard work implementing a Web Services class for AS3. It will come in handy for many of us.
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
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!
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.
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.
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!
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?
@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/
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
Good to know that worked, kudos to Brandon ( http://www.headwindslab.net ) for providing me with that link.
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