Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: Webservice calls in Flash9/AS3

  1. #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.

  2. #2
    Oh lord, someone please tell me it isn't. This could create huge headaches for me in migrating to AS3 for work.

  3. #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.

  4. #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.

  5. #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...

  6. #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.


    Great, now even Kirupa is { facebooking | twittering }

  7. #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;
    		}
    	}
    }
    Good judgment comes from experience.
    Experience comes from bad judgment.
    personal site ::: Game Dev

  8. #8
    Is there a way to load flash files into Flex and access the webservices through flex? If there is it will be of great help.

  9. #9

    Confused about the class below

    Tessaract,

    A question about the class you provided, can it be used to call a ASP.NET web service?

  10. #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!!

  11. #11

    WebService 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.

  12. #12
    Can this code been firsthand used?

  13. #13

    AS3 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/

  14. #14
    Didn'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..

  15. #15
    Yeah 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...

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012