You are here: Recent News » wsdl2as

 

wsdl2as

wsdl2as is a Java application for generating ActionScript 3 stub code to access a SOAP webservice as defined by a WSDL file. The result of running it should typically be a .as file defining a class named after the service, which contains ActionScript methods named after the operations in the WSDL.

It is only intended to work with document/literal style services!

Why?

Flex already includes WebService support, but all the code is dynamically-typed, which means the compiler is less likely to spot coding errors caused by changes in the server-provided interface.

Programming against wsdl2as-generated code will give the compiler a chance to spot when you try to call a method that doesn’t exist, or pass a parameter who’s type has changed. Also, when the WSDL embeds documentation describing the service, this documentation will be copied to the generated AS code, so that it may be visible to syntax-aware editors.

TODO

  • A proper release. The download on this page is an early alpha
  • Improve Type mapping. Enabling the –mapping asxsd option will generate AS3 value-objects and ‘marshaling/unmarshaling’ code to convert between XML and VOs, but the mapping code generator needs improving as there are many XML Schema constructs that are not yet handled

Getting wsdl2as

This is an early demo release! Have a play, and report any problems to the osflash@osflash.org mailing list, or to me directly (dave at badgers-in-foil.co.uk).

You can grab a Java ‘Jar’ file from here:

http://www.badgers-in-foil.co.uk/projects/wsdl2as/releases/wsdl2as-0.1-SNAPSHOT-jar-with-dependencies.jar

Running wsdl2as

Having downloaded the above jar file, you can execute wsdl2as like this:

java -jar wsdl2as-0.1-SNAPSHOT-jar-with-dependencies.jar

This will cause wsdl2as to output a brief help message:

<usage: wsdl2as [--mapping strategy] -o dir
    --mapping <strategy>   Strategy to map XML to AS3 values: 'none' (the
                           default) or 'asxsd'
 -o,--output <dir>         Output directory for generated code

You must supply two extra arguments to generate some code,

  • The output directory, using the -o dir option
  • The name or URI of the WSDL file to be processed

For example:

java -jar wsdl2as-0.1-SNAPSHOT-jar-with-dependencies.jar -o out --mapping asxsd "http://localhost:8080/axis2/services/version?wsdl"

Getting the wsdl2as Source Code

You can get the code from subversion:

http://svn.badgers-in-foil.co.uk/wsdl2as/trunk/

This project has various dependencies

‘metaas’:

http://www.badgers-in-foil.co.uk/projects/metaas/

‘asxsd’: only available in Subversion, unfortunately:

http://svn.badgers-in-foil.co.uk/asxsd/trunk/

It also requires a few components from the Eclipse ‘Web Standards Tools’ plugin, and the ‘Eclipse Modeling Framework’. In the install of Eclipse I have in front of me right now, the files in question are,

plugins/org.eclipse.wst.wsdl_1.0.101.v200609141945.jar plugins/org.eclipse.xsd_2.2.1.v200609210005.jar plugins/org.eclipse.emf.common_2.2.1.v200609210005.jar plugins/org.eclipse.emf.ecore_2.2.1.v200609210005.jar plugins/org.wsdl4j_1.4.0.v200607181917/lib/wsdl4j.jar

Example Code

Here is some code that makes use of the generated classes. Apache Axis 2 comes with an example called ‘versionservice’ which just defines a single operation which returns the version of Axis currently running. Having generated AS code against the WSDL of this service, here is the code required to access the service:

TODO: slightly out of date

package {
	import flash.display.Sprite;
	import flash.text.TextField;
	import org.apache.ws.axis2.versionLocator;
	import org.apache.ws.axis2.versionSOAP11BindingStub;
	import org.apache.ws.axis2.Call;
 
	public class Test extends Sprite {
		public function Test() {
			var display_txt:TextField = new TextField();
			display_txt.text = "Hello World!\n";
			addChild(display_txt);
			stage.addChild(new Output(stage));
 
			try {
				go(display_txt);
			} catch (e:Error) {
				display_txt.text = e.toString();
			}
		}
		private function go(display_txt:TextField):void {
			var locator:versionLocator = new versionLocator();
			var binding:versionSOAP11BindingStub
				= locator.getversionSOAP11port0();
			var call:Call = binding.getVersion(<getVersion xmlns="http://axisversion.sample/xsd"/>);
			call.onData = function(data:XML):void {
				display_txt.text = data.toXMLString();
			}
			call.onFault = function(msg:String):void {
				display_txt.text = "Bugger!";
			}
			call.call();
		}
	}
}

wsdl2as.txt · Last modified: 2006/12/20 16:32 by david.holroyd