XFireHome M5M6-SNAPSHOTDevelopersDeveloper Space |
Creating a Service From a ClassIn 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 = builder.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(ObjectService.SERVICE_IMPL_CLASS, YourServiceImpl.class); InvokersXFire 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. Using a different bindingYou'll notice above the line of code that looks like this: ServiceFactory factory = new ObjectServiceFactory(xfire.getTransportManager(), null); The second argument in the ObjectServiceFactory is the BindingProvider. BindingProviders manage how xml is bound to objects. For instance the default BindingProvider maps objects to POJOS, but there is also a BindingProvider which maps xml to Document objects. To use the message binding: ServiceFactory factory = new ObjectServiceFactory(xfire.getTransportManager(), new MessageBindingProvider()); |