Building Web Services with JAX-WS – Basics Refresher & Tutorial

Smart and funny ways to save money during recession

A quick refresher of JAX-WS basics!

—————————————————————————————————-
Concepts:
—————————————————————————————————-

  1. JAX-WS stands for Java API for XML Web Services.
  2. It allows to write message-oriented as well as RPC-oriented web services
  3. A web service invocation is done using an xml based protocol like SOAP
  4. The developer does not generate or parse SOAP messages.JAX-WS runtime takes care of it.
  5. A service endpoint interface or service endpoint implementation (SEI) is a Java interface or class, respectively, that declares the methods that a client can invoke on the service.
  6. An interface is not required when building a JAX-WS endpoint. The web service implementation class implicitly acts as an SEI.
  7. Jax-WS clients call a service through a port, a local object that acts as a proxy for the remote service.

—————————————————————————————————-
Requirements of a JAX-WS Endpoint:
—————————————————————————————————-

  1. The implementing class must be annotated with either the javax.jws.WebService or javax.jws.WebServiceProvider annotation.
  2. The implementing class may explicitly reference an SEI through the endpointInterface element of the @WebService annotation, but is not required to do so. If no endpointInterface is specified in @WebService, an SEI is implicitly defined for the implementing class.
  3. The business methods of the implementing class must be public, and must not be declared static or final.
  4. Business methods that are exposed to web service clients must be annotated with javax.jws.WebMethod.
  5. Business methods that are exposed to web service clients must have JAXBcompatible parameters and return types.
  6. The implementing class must not be declared final and must not be abstract.
  7. The implementing class must have a default public constructor.
  8. The implementing class must not define the finalize method.
  9. The implementing class may use the javax.annotation.PostConstruct or javax.annotation.PreDestroy annotations on its methods for life cycle event callbacks.

—————————————————————————————————-
Steps to create a Service:
—————————————————————————————————-

  1. Define a Service (web service endpoint) by annotating the class with @WebService annotation
  2. If an explicit interface is used then it can be specified by adding the endpointInterface element to the @WebService annotation
  3. Use endpoint implementation class and the wsgen tool to generate the web service artifacts that connect a web service client to the JAX-WS runtime.
  4. Package it as a war and deploy. Application Server generates the web service artifacts (which are used to communicate with clients) during deployment.

—————————————————————————————————-
Steps to create a Client:
—————————————————————————————————-

  1. Uses the javax.xml.ws.WebServiceRef annotation to declare a reference to a web service. @WebServiceRef uses the wsdlLocation element to specify the URI of the deployed service’s WSDL file.
  2. Retrieve a port to the service. The port is created at development time by the wsimport tool, which generates JAX-WS portable artifacts based on a WSDL file.
  3. Invoke the web service method

RK

Smart and funny ways to save money during recession

This entry was posted in Technology and tagged , , . Bookmark the permalink.

One Response to Building Web Services with JAX-WS – Basics Refresher & Tutorial

  1. This topic is quite hot in the net at the moment. What do you pay attention to while choosing what to write ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s