Sunday, February 13, 2011

Required Annotations for Web Service - Java

Java6 provides some annotations for creating Webservice, when the strategy is bottom-up. Here I describe some required annotations for that.

1. @WebService - This annotation is used to identified the WebService name in the SEI.
2. @WebMethod - This annotation is used to identified the WebService Operation in SEI.
3. @WebParam - This annotation is used to identified the WebService Operation's parameter name in SEI.
4. @WebResult - Customizes the mapping of the return value to a WSDL part and XML element

Thursday, February 10, 2011

Writing Web Services using Bottom-Up approch

In this approch, you have to do the following steps:

1. Create SEI (Service Endpoint Interface) and its implementation class. The SEI defines the methods that are available for service consumer. Those methods are called Operations - There are two basic patterns for creating an SEI:
   • Green field development
   You are developing a new service from the ground up. When starting fresh, it is best to start by creating the SEI first. You can then distribute the SEI to any developers that are responsible for implementing the services and consumers that use the SEI.

   • Service enablement
   In this pattern, you typically have an existing set of functionality that is implemented as a Java class and you want to service enable it. This means that you will need to do two things:
      a.Create an SEI that contains only the operations that are going to be exposed as part of the service.
      b.Modify the existing Java class so that it implements the SEI.

2. Add the required annotations -

3. Generate WSDL for contract of the service. This step is optional, if you treat SEI as a contract for your service then no need to create WSDL.

4. Publish the web service - You can use any web container to publish the service. The process is the same as adding servlet for web application.


Example:

Create POJOs for the Service:






Create SEI:


Create SIB:


Publish the service:


Create Service Consumer:


Result:


Download the complete example