Saturday, April 18, 2009

How to generate a wsdl2 file using Axis2 java2wsdl

If you are not familiarized with WSDL 2.0 creating one of these files from scratch for your web service can be a daunting experience. Axis2 provides a java2wsdl tool that can make this task easier by automatically creating the file for you.

Download the latest version here and after decompressing the file, set a system variable pointing to the installation path by adding the following line to your Linux "/etc/profile" file:

export AXIS2_HOME="/opt/Programs/axis2-1.4.1"

The command line tool has the following options available:

-o output directory
-of output file name for the WSDL
-sn service name
-l address of the port for the WSDL
-cp list of classpath entries - (urls)
-tn target namespace for service
-tp target namespace prefix for service
-stn target namespace for schema
-stp target namespace prefix for schema
-st style for the WSDL
-u use for the WSDL
-nsg fully qualified name of a class that implements NamespaceGenerator
-sg fully qualified name of a class that implements SchemaGenerator
-p2n [,,] to assign all types to a single namespace
-efd setting for elementFormDefault (defaults to qualified)
-afd setting for attributeFormDefault (defaults to qualified)
-xc class1 -xc class2... extra class(es) for which schematype must be generated.
-wv <1.1/2.0> wsdl version - defaults to 1.1 if not specified
-dlb generate schemas conforming to doc/lit/bare style

Here is a sample of how to use the command to generate a WSDL 2.0 file for "MyService":

/axis2-1.4.1/bin/ -wv 2.0 -o /workspace/myApp/src/META-INF/ -of MyService.wsdl -sn MyService -cp:/workspace/myApp/target/classes -cn sample.package.MyService

Notice how the classpath is specified, each location is separated with a colon, in case you have multiple entries it with look like this:


This command also has an Eclipse plugin but it doesn't generate files for the WSDL 2.0 version, in the mean time it can make your life easier, just bear in mind that in case you have a complex service it is possible that you will have to tweak the file a bit to make it work, but for a simple test it can work like a charm ;)

blog comments powered by Disqus