EJB stateless session bean as web service
- Import the sample DateFormatter (EJB 3.0) project provided in the downloads.
- This project has a stateless session bean named DateFormatterService already created in it.
- The DateFormatterService has the service method which formats the given date object into a String whose format is
"EEE, MMM d, yyyy"
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.
- To create a JAX-WS web service, add an annotation
@WebServicejust above the @Stateless anotation in theDateFormatServicebean. 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.
- After importing the project, right-click DateFormatterService bean, Web Services > Create web service.
- 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
- In the first slidebar, slide till “Assemble service” and in the second, slide to “No client”.
- Click next. In the Web Service EJB configuration select HTTP bindings.
- 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.
- 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.
- Once the explorer opens, in the left panel, select the operation(formatDate here) to be executed.
- 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




0 Comments.