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

Creating a service

Steps

  1. Create your Schema
  2. Create your XMLBeans
  3. Create your Service
  4. Register your service

Assuming that you know how to do steps 1 and 2, lets pick up at step 3. Create your service class:

package org.codehaus.xfire.xmlbeans;

import net.webservicex.GetWeatherByZipCodeDocument;
import net.webservicex.GetWeatherByZipCodeResponseDocument;
import net.webservicex.WeatherForecasts;

public class WeatherService
{
    public GetWeatherByZipCodeResponseDocument GetWeatherByZipCode( GetWeatherByZipCodeDocument body )
    {
        GetWeatherByZipCodeResponseDocument res =
            GetWeatherByZipCodeResponseDocument.Factory.newInstance();
        
        WeatherForecasts weather = 
            res.addNewGetWeatherByZipCodeResponse().addNewGetWeatherByZipCodeResult();
        
        weather.setLatitude(1);
        weather.setLongitude(1);
        weather.setPlaceName("Grand Rapids, MI");
        
        return res;
    }
}

Notice that we used the "Document" Types, not the "GetWeatherByZipCode" class. After you've created your service class you simply need to register it:

XFire xfire = XFireFactory.newInstance().getXFire();
XmlBeansServiceBuilder builder = new XmlBeansServiceBuilder(xfire.getTransportManager());

Service service = builder.create(WeatherService.class);

xfire.getServiceRegistry().register(service);

XFire will not expose your service as the "WeatherService" and will generate WSDL for you automatically!

Stub Generation from WSDL

XFire has some (experimental) capability to generate a service from a wsdl file. First you'll need to generate your xmlbeans from the wsdl file using the XMLBeans SchemaCompiler. Then you'll need to use XFire's XMLBeans generation ant task:

<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"
              strategy="org.codehaus.xfire.xmlbeans.generator.ServerGenerationStrategy" />