EJB stateless session bean as web service

EJB stateless session bean as web service
This article provides a view of how a stateless session bean can work as a web service.Follow the step by step instructions listed below for exposing session bean as web service.

Getting started

  1. Import the sample DateFormatter (EJB 3.0) project provided in the downloads.
  2. This project has a stateless session bean named DateFormatterService already created in it.
  3. The DateFormatterService has the service method which formats the given date object into a String whose format is "EEE, MMM d, yyyy"

Creating the web service

Now we will expose the “formatDate” method in the DateFormatterService bean as a web service. Though JAX-WS is advanced version of Web Service we will look into JAX-RPC version as well.

JAX-WS

  1. To create a JAX-WS web service, add an annotation @WebService just above the @Stateless anotation in the DateFormatService bean. Building the project creates a service under services.

2. Add a router to transfer the soap messages over http. Right-click the service that is created under services and select Create router module(EndpointEnabler). In the Create Router Modules window, select EJB Web Service binding as HTTP. Select finish. This creates a DateFormatter_HTTPRouter.

Done! You have created JAX-WS web service for stateless session bean.

JAX-RPC

  1. After importing the project, right-click DateFormatterService bean, Web Services > Create web service.
  2. In the Web Service creation window, provide the following values:
    • Web service type: Bottom up EJB Web Service
    • Service implmentation: DateFormatterService
    • Web service runtime: IBM Websphere JAX-RPC
    • Service project: DateFormatter
    • Service EAR project: DateFromatterEAR
  3. In the first slidebar, slide till “Assemble service” and in the second, slide to “No client”.
  4. Click next. In the Web Service EJB configuration select HTTP bindings.
  5. Click next. In the Web Service EJB identity window select the method which is to be exposed as web service.

6. As we are not publishing this service to a UDDI registry, click finish.

Done! You have created JAX-RPC web service for stateless session bean.

Testing the web services

  1. After creating the service, you are ready to test the web service using the test explorer, provided the application is added to server. Right-click on the service which is created(DataFormatter > Services > <service name>) and select Test with Web Services Explorer.
  2. Once the explorer opens, in the left panel, select the operation(formatDate here) to be executed.
  3. Provide the input date and click on Go button.

Get the source from  – http://www.ibm.com/developerworks/webservices/tutorials/ws-ejbstateless/downloads.html

The content from ibm site – http://www.ibm.com/developerworks/webservices/tutorials