Chapter 2. Developing a JAX-WS Web Service

Java 7 supports Java API for XML Web Services (JAX-WS) 2.2.4 or later. In this chapter, we shall discuss the procedure for using the new -clientjar option in the wsimport task/tool in Java 7. We require a Java IDE that supports Java 7 and a web container that also supports Java 7. We need to install the following JDK and software as discussed in the previous chapter:

  • Java SE 7
  • NetBeans IDE 7.0.1
  • Oracle GlassFish Server 3.1.1

The sample NetBeans project is available in the downloadable sample ZIP file. This chapter has the following sections:

  • What is new in Java 7 wsimport?
  • Creating a NetBeans project
  • Creating the implementation class
  • Creating the WSDL
  • Creating the deployment descriptors
  • Creating a client class
  • Creating the deployment targets
  • Creating an Apache Ant build file
    • Building and deploying the service
    • Building the client
    • Running the client
  • Testing the web service
  • Using the wsimport tool from the command line

The wsimport tool or the wsimport Ant task is used to generate JAX-WS portable artifacts, which are used for invoking a web service from a web service client, from a service Web Services Description Language (WSDL). Specifically, wsimport generates the following artifacts:

  • Service Endpoint Interface (SEI)
  • Service class
  • If a wsdl:fault is present in the WSDL, an Exception class
  • Java classes mapped from schema types
  • If a wsdl:message is present, asynchronous response beans

Java 6 wsimport limitation

The problem with Java 6 wsimport is that the JAX-WS runtime needs to fetch the WSDLs from the endpoint each time a service instance is created, which could incur a network overhead. The WSDL location is saved in the generated artifacts and the JAX-WS runtime fetches the metadata, which is useful if the endpoint policy or the service definition has changed. In the absence of the runtime fetch of the metadata, the clients would need to be regenerated if the endpoint policy or the service definition have changed. JAX-WS runtime may have access to local WSDLs using various methods such as a Service API, a jax-ws-catalog.xml file, or making the WSDL available at a relative local location and using the -wsdlLocation option when running the wsimport tool.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.242