O'Reilly logo

Java Web Services in a Nutshell by Kim Topley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ServiceFactory and the Service Interface

In Chapter 2, you saw that in order to get a stub for a web service endpoint interface, it was first necessary to obtain a reference to a Service object, using code like this:

BookService_Impl  service = new BookService_Impl(  );
BookQuery bookQuery = (BookQuery)service.getBookQueryPort(  );

BookInfo[] books = bookQuery.getBookInfo(  );

where BookService_Impl is a class generated by wscompile that implements the javax.xml.rpc.Service interface. As noted in Chapter 2, there is no standard naming convention for this generated class (although the JAX-RPC specification recommends one); therefore, making use of the class name in this way introduces a dependency in your code on a specific JAX-RPC implementation. Although there is nothing that you can do about this if your client application uses the stubs generated by wscompile, it is possible to make your code more portable if you use dynamic proxies or the dynamic invocation interface instead of static stubs, or if you build a J2EE application client instead of a standalone J2SE client. In order to see how this can be done, it is necessary first to look in more detail at the Service interface and the ServiceFactory class to which it is related.

The ServiceFactory Class

ServiceFactory is an abstract class that can be used to create Service objects in a portable manner. The public methods of ServiceFactory are shown in Example 6-2.

Example 6-2. The ServiceFactory class

public abstract class ServiceFactory ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required