Sunday, January 9, 2011

Web Service Development Strategies

When developing a Web Service Endpoint (the server-side) you have the option of starting from Java (bottom-up development), or from the abstact contract (WSDL) that defines your service (top-down development). If this is a new service (no existing contract), the bottom-up approach is the fastest route; you only need to add a few annotations to your classes to get a service up and running. However, if you are developing a service with an already defined contract, it is far simpler to use the top-down approach.

Bottom-up use cases:
• Providing a new service, and you want the contract to be generated for you.


Top-down use cases:
• Replacing the implementation of an existing Web Service, and you can't break compatibility with older clients.
• Exposing a service that conforms to a contract specified by a third party (e.g. a vender that calls you back using an already defined protocol).
• Creating a service that adheres to the XML Schema and WSDL you developed by hand up front.

There are no of tools for working with Top-down and Bottom-up Web Service Development.

1. JBossWS is one of the implementation of JAX-WS, provided by JBoss.
Bottom-up
• JBossWS - wsprovide :- Generates JAX-WS portable artifacts, and provides the abstract contract. Used for bottom-up development(Java).

Top-down
• JBossWS - wsconsume :- Consumes the abstract contract (WSDL and Schema files), and produces artifacts for both a server and client. Used for top-down and client development.

2. Sun's implementation of JAX-WS, available with JDK6 distribution.
Bottom-up
• wsgen :- Generates JAX-WS portable artifacts, and provides the abstract contract. Used for bottom-up development(Java).

Top-down
• wsimport :- Consumes the abstract contract (WSDL and Schema files), and produces artifacts for both a server and client. Used for top-down and client development.

Method Overloading in WSDL

There is no direct way to overload java method in WSDL, WSDL does not support Overloading mechanism, but you can achive this through other ways. This will be done through RequestWrapper and ResponseWrapper Annotation. Those Annotations are need to be included in Service Implementation Bean(SIB). There is no harm if you add those in Service Implementation(SI). But SIB is mandatory.

@RequestWrapper - have localName, targetNamespace and class. For method overloading you have to specify class name field.

@ResponseWrapper - have same fileds as RequestWrapper, here also you have to specify class name field.

Code Snippet for Service Implementation:


Code Snippet for Service Implementation Bean:


Use this commeand to generate server side artifact and WSDL:
I am using JAX-WS with Jdk6.

prabir$> wsgen -keep -wsdl -cp bin HelloServer -d client

Here HelloServer is the Service endpoint implementation class also known as Service Implementation Bean.