XFire

Home
Bug/Issue Reporting
Download
FAQ
Get Involved
License
News
Stack Comparison
Support
User's Guide
XFire Team

M5

Javadocs
Reports

M6-SNAPSHOT

Javadocs
Reports

Developers

Developer Space
CVS
Building
Architecture
Interesting Projects
Release Process

Warning

This will probably not work for you. We are working hard on improved client support. If you would like to join the team, please contact us!

Web service clients can be created from a WSDL file using an Ant task. Creating a client service is a two step process. First, you need to use XMLBeans to generate types from the WSDL document. Next, XFire's stub generator is used to create a client. Unfortunately, this process will not work for RPC/Encoded services, however rpc/encoded documents can still be constructed by hand using the method outlined in the previous section.

Generating XMLBeans

While, you may also find it helpful to read the XMLBeans documentation, a quick summary of how to generate XMLBeans is provided here.

Generating XMLBeans just requires a few lines in your Ant build file or your Maven "maven.xml".

<java classname="org.apache.xmlbeans.impl.tool.SchemaCompiler"
          classpathref="task.path"
          fork="true">
      <arg value="-d"/>
      <arg value="$\{destination.class.directory\}"/>
      <arg value="$\{basedir\}/src/test-schemas"/>
    </java>

This will output the XMLBeans classes into the directory "${destination.class.directory}". It looks in the "${basedir}/src/test-schemas" directory to find any WSDL and XSD files which it uses to generate types. You also need to have a path set up which has the XMLBeans jar on it - in this case it is called "task.path".

Its also possible to generate a jar for the XMLBeans classes like so:

<java classname="org.apache.xmlbeans.impl.tool.SchemaCompiler"
          classpathref="task.path"
          fork="true">
      <arg value="-out"/>
      <arg value="$\{output.dir\}/output.jar"/>
      <arg value="$\{basedir\}/src/test-schemas"/>
    </java>

where you replace "${output.dir}/output.jar" with the path name of where you want the resultant jar.

Generating a Client

Next, we need to add one more section your build file. This will generate your client.

<path id="generate.path">
      <pathelement path="..."/>
      ... more path elements
    </path>   

    <taskdef name="generate" 
             classname="org.codehaus.xfire.xmlbeans.generator.GeneratorTask"
             classpathref="generate.path"/>

    <generate overwrite="true"
              package="org.codehaus.xfire.weather"
              outputDir="$\{src.output.dir\}"
              wsdl="${basedir}/src/test-schemas/WeatherForecast.wsdl"
              classpathref="generate.path" />

This takes the "WeatherForecas.wsdl" file and generates a control interface in the package "org.codehaus.xfire.weather." The classpath "generate.path" needs to have both XMLBeans and the classes generated in the previous step in it. Source files will be generated in "${src.output.dir}".

Using the Client

Once you've generated your stub, the hard part is done. Operations for the service will appear as methods on the resultant client. To invoke the service, just invoke a method on the client.

Typical usage of a client would be like so:

ItemLookupDocument req = ItemLookupDocument.Factory.newInstance();

// .... Fill in the request object

// Invoke the service
AWSECommerceServiceClient client = new AWSECommerceServiceClient();
ItemLookupResponseDocument res = client.ItemLookup(req);

// Do stuff with the response