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

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 ...

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