Codehaus XFire

Documentation

Quicklinks

Developers

Sponsors

Creating a Service From a Class

In the simplest case you will have a service modeled as a java object which you would like to make a web service. This is easy enough through the ServiceFactory interface:

XFire xfire = XFireFactory.newInstance().getXFire();
ServiceFactory factory = new ObjectServiceFactory(xfire.getTransportManager(), null);

Service service = factory.create(YourService.class);

This will create a SOAP 1.1 Wrapped/Document style service for your class. If you have any complex types (i.e. not string, int, long, boolean, etc) XFire will automatically try and serialize these for you (using the Aegis binding). After you create the service you must register it:

xfire.getServiceRegistry().register(service);

You can also gain more control over how your service is configured but using a more verbose method to build your service:

XFire xfire = XFireFactory.newInstance().getXFire();
ServiceFactory factory = new ObjectServiceFactory(xfire.getTransportManager(), null);

Service service = factory.create(YourService.class,
                                 "Name",
                                 "namespace",
                                 null);

If you used an interface to build the service (recommended), you can set the service implementation like so:

service.setProperty(ObjectInvoker.SERVICE_IMPL_CLASS, YourServiceImpl.class);

Invokers

XFire uses Invokers to control how your service is invoked. The default is that your service class is instantiated just once.

In a lot of cases you don't want XFire to manage your service objects. For instance if you wanted to use a factory to create your services you could write your own service Invoker which did that. Or if you already have an instance of an object that you wanted to invoke you could write an invoker to just use that object.

See the Invoker, ObjectInvoker, and BeanInvoker classes for examples of invokers and the API. For an example usage, see Invokers.