JAX-RPC and J2EE 1.4 Application Clients

So far, you have seen two different ways for a client to get a reference to the Service object that it needs before it can invoke the methods of a web service:

  • Direct instantiation of the Service implementation class. This is the technique used in Chapter 2. Although this works, it requires the application to know the name of the generated Service class, which makes it dependent on a particular JAX-RPC implementation.

  • Using a ServiceFactory to create a Service object, as shown earlier in this chapter. While this frees your code from dependency on the JAX-RPC implementation, the object you get back implements only the Service interface, not the actual interface defined by the web service (such as BookService). Therefore, it doesn’t have methods such as getBookQueryPort( ) that directly return references to the service endpoint interface.

If you are writing a J2SE application client, these are the only choices available to you. However, J2EE 1.4 allows container-resident clients to retrieve references to Service objects defined in their JNDI environment. Furthermore, these Service objects can be instances of generated classes such as BookService. By using this facility, you can write code that is vendor-independent (in the sense that it does not rely on the actual name of the generated Service class), while still having the convenience of using methods such as getBookQueryPort( ). This section shows how to make use of this feature by demonstrating ...

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.