Skip to end of metadata
Go to start of metadata

This examples highlights how to

  • Create a Service using the API
  • Expose that Service using XFire's embedded HTTP server
  • Create a client for the service

You can also use XFire with Servlets or Spring Remoting, this is just one of your many options with XFire!

Creating the Service

The first task is to write our Service. Further down we'll be showing how to create a Client. Java Proxies require an interface, and since that is how the Client API works, we'll be writing our interface first. For this example, we're going to create a simple class which echoes back a String:

We'll also need to write an implementation:

Next we're going to write a class called ServiceStarter. This class creates a Service from the ServiceFactory and also starts up an instance of the XFireHttpServer.

ServiceFactorys are responsible for creating Services and configuring them in XFire. You'll see in other sections that there is an AnnotationServiceFactory as well and you can use that with JSR 181 Annotations.

The XFireHttpServer uses Jetty underneath so make sure that you have it on your classpath. 

If you use maven, here are all the dependencies you'll need:

Starting the service and the Client

Using the Client is very similar. Once again we'll are creating a Service from an ObjectServiceFactory. This is because the Service object holds metadata about our Service. Our client needs this metadata to understand how the Service works. (NOTE: we also support WSDL code generation and dynamic clients if you didn't write the service or don't have the interface on your classpath). The XFireProxyFactory is then responsible for creating a proxied interface which will invoke this service.

At the end, all we need to do is invoke "echo.echo("Hello World")" and "Hello World" should be sent right back to you!

If you were going to create a client from .NET you would be able to find the WSDL at http://localhost:8191/Echo?wsdl.

Labels: