Results 1 to 15 of 22
Thread: Webservice calls in Flash9/AS3
-
April 29th, 2007, 05:24 AM #1
Webservice calls in Flash9/AS3
Hi,
I'm migrating an app from AS2 to AS3, which has fairly substantial use of webservices using the as2 Webservice classes.
Is there an AS3 equivalent for these classes? I read on one forum that there is nothing provided for webservices in AS3, and you'd have to serialize/deserialize the soap packets manually yourself - surely this can't be the case?!
thanks
Marcus.
-
April 29th, 2007, 09:31 AM #2
Oh lord, someone please tell me it isn't. This could create huge headaches for me in migrating to AS3 for work.
-
April 29th, 2007, 01:38 PM #3
Maybe you should make a static class with helper functions to replace the AS2 functions that you're used to.
That way, you can import your static class and use the functions right out of the bag, no migration needed.
Last edited by Rezmason; April 29th, 2007 at 01:44 PM.
-
April 29th, 2007, 02:02 PM #4
That's what I kinda did. Made my own NetCommunications class that worked with the webservices. Didn't make it static though 'cause I'd be making multiple calls simultaneously from different objects all with different targets and whatnot.
-
April 29th, 2007, 03:24 PM #5
So does anyone have an sample of an AS3 class that will deserialize the given data objects into a soap body, perform the complete soap request, and serialize the soap response into a new data object?
Am I missing something here? Is there a less obvious package in Flash CS3/AS3 that already does all this for you? I can only hope I am, cause it seems like a massive failure on Adobe's part if the AS library has regressed to exclude this fairly important functionality...
-
July 3rd, 2007, 01:26 AM #6
Somebody e-mailed me a similar question, and I cannot find any built-in WebService/SOAP/WSDL support in Flash CS3. That's unfortunate, for it would seem like a useful feature these days, so I hope I am simply not looking hard enough.
I know Flex 2 supports making web service calls using built-in classes, so maybe there is a way to use the Flex 2 classes in Flash CS3.
-
July 3rd, 2007, 08:51 AM #7
Here is a class I had to build recently for a big project. It worked well, but I am sure it can be improved upon.
Code:package { import flash.net.*; import flash.xml.XMLDocument; import flash.events.Event; import flash.events.ErrorEvent; import flash.events.HTTPStatusEvent; public class WebService { private var urlLoaderService:URLLoader; public var soap12:Namespace = new Namespace("http://www.w3.org/2003/05/soap-envelope"); public var xsi:Namespace = new Namespace("http://www.w3.org/2001/XMLSchema-instance"); public var xsd:Namespace = new Namespace("http://www.w3.org/2001/XMLSchema"); public var returnFunction:Function; public function WebService($parent:DepthMonitor) {} public function loadWebService($feedURL:String,$returnFunction:Function,$identifier:String,$identifier2:String=null):void { var feedType:String = $feedURL.split("=")[1]; var urlRequest:URLRequest = new URLRequest($feedURL); returnFunction = $returnFunction; urlRequest.method = URLRequestMethod.POST; urlRequest.requestHeaders.push(new URLRequestHeader("Content-Type", "application/soap+xml")); urlRequest.data = returnCorrectXML(feedType,$identifier,$identifier2); urlLoaderService = new URLLoader(); urlLoaderService.dataFormat = URLLoaderDataFormat.TEXT; urlLoaderService.addEventListener("complete", onServiceLoaded); urlLoaderService.addEventListener("ioerror", ifServiceFailed); urlLoaderService.load(urlRequest); } public function onServiceLoaded(e:Event):void { var d:XML = new XML(urlLoaderService.data); returnFunction(d); urlLoaderService.data = null; } public function ifServiceFailed(e:ErrorEvent):void { trace("Couldn't load "+ returnFunction +" because ::: " + e); } /* -------------------------------------------------------------- */ /* REPOSITORY OF FEED CONFIGURATIONS */ /* -------------------------------------------------------------- */ public function returnCorrectXML(feedType:String,feedIdentifier:String,feedIdentifier2:String):XML { var rXML:XML = <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body/> </soap12:Envelope> ; switch (feedType) { case "feed1": rXML.soap12::Body.appendChild( <feed1 xmlns="http://www.something.com/"> <feed1Data>{feedIdentifier}</feed1Data> </feed1> ); break; case "feed2": rXML.soap12::Body.appendChild( <feed2 xmlns="http://www.something.com/"> <feedData>{feedIdentifier}</feedData> <feedData2>{feedIdentifier2}</feedData2> </feed2> ); break; default: trace("can't find a SOAP request document conforming to this parameter : " + feedType); break; } return rXML; } } }
-
July 23rd, 2007, 11:00 AM #84neatocoder
postsIs there a way to load flash files into Flex and access the webservices through flex? If there is it will be of great help.
-
August 2nd, 2007, 03:00 PM #93Registered User
postsConfused about the class below
Tessaract,
A question about the class you provided, can it be used to call a ASP.NET web service?
-
October 1st, 2007, 02:29 PM #10
Can someone post a sample usage for the class above?
Anyone else discovered any methods for accessing webservices in AS3?
I'm dying here ... just found out that AS3 doesn't support webservices, have a project due today that has to use them ... ACK!!
-
October 2nd, 2007, 01:34 PM #111Registered User
postsWebService communication succesful
I think I've managed to call a webservice using the class provided here as my base. Had to do some modifications thou and so far it ONLY supports sending a single String to the webservice if needed (haven't tried with other data types). Another thing, haven't worked on the decoding the response, but I think at least having it RAW should be useful so far. Here's the class modified..
Code:package { import flash.net.*; import flash.xml.XMLDocument; import flash.events.Event; import flash.events.ErrorEvent; import flash.events.HTTPStatusEvent; public class WebService { private var urlLoaderService:URLLoader; public var soap12:Namespace = new Namespace("http://www.w3.org/2003/05/soap-envelope"); public var xsi:Namespace = new Namespace("http://www.w3.org/2001/XMLSchema-instance"); public var xsd:Namespace = new Namespace("http://www.w3.org/2001/XMLSchema"); public var returnFunction:Function; public function WebService() {} public function loadWebService($feedURL:String,$returnFunction:Function,$parametro:String=null,$valor:String=null):void { var webMethod:String = $feedURL.split("=")[1]; var urlRequest:URLRequest = new URLRequest($feedURL); returnFunction = $returnFunction; urlRequest.method = URLRequestMethod.POST; urlRequest.requestHeaders.push(new URLRequestHeader("Content-Type", "application/soap+xml; charset=utf-8")); urlRequest.data = returnCorrectXML(webMethod,$parametro,$valor); urlLoaderService = new URLLoader(); urlLoaderService.dataFormat = URLLoaderDataFormat.TEXT; urlLoaderService.addEventListener("complete", onServiceLoaded); urlLoaderService.addEventListener("ioerror", ifServiceFailed); urlLoaderService.load(urlRequest); } public function onServiceLoaded(e:Event):void { var d:XML = new XML(urlLoaderService.data); returnFunction(d); urlLoaderService.data = null; } public function ifServiceFailed(e:ErrorEvent):void { trace("Couldn't load "+ returnFunction +" because ::: " + e); } /* -------------------------------------------------------------- */ /* REPOSITORY OF FEED CONFIGURATIONS */ /* -------------------------------------------------------------- */ public function returnCorrectXML(metodo:String,parametro:String,valor:String):XML { var rXML:XML = <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body/> </soap12:Envelope> ; if (parametro != null) { rXML.soap12::Body.appendChild( <{metodo} xmlns="http://tempuri.org/"> <{parametro}>{valor}</{parametro}> </{metodo}> ); } else { rXML.soap12::Body.appendChild( <{metodo} xmlns="http://tempuri.org/" /> ); } return rXML; } } }
USAGE
__________________________Code:var ws:WebService; ws = new WebService(); ws.loadWebService("http://localhost/webservices/Service1.asmx?op=HelloWorld",callback); /****/ public function callback(result:XML):void { trace(result); }
Hope this helps someone.. Basically it is forming the soap request manually.. i'm still working on it for the decoding part.. and also the send array as a parameter.
-
October 9th, 2007, 03:49 AM #121Registered User
postsCan this code been firsthand used?
-
October 27th, 2007, 02:42 PM #133Registered User
postsAS3 web service class
Hey guys, I just built this web service class and it works with the web services I've used. I hope it can help someone:
Download it here:
http://alducente.wordpress.com/2007/...s3-release-10/
-
October 28th, 2007, 09:15 AM #14910Registered User
postsDidn't do any extensive testing, but I tried a couple simple calls on a few different services and that seems to work great, alducente.. Thanks for sharing..
-
October 28th, 2007, 11:02 AM #153Registered User
postsYeah I tried to make it as modular as possible but it was originally geared towards services built using ASP.NET, I'm not totally sure what other kinds of services exist out there, I'm pretty new to web services and only got started on it because of a project at work that required it. Glad it works for someone else...

Reply With Quote

Bookmarks