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 ...
Get Java Web Services in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.