Before you start
About this tutorial
This tutorial describes the different ways of creating web services for EJB stateless session beans in Rational Software Architect, and how to test the web services using the web service test explorer. An EJB sample application is provided.
The main objective of this tutorial is to provide details on creating JAX-WS and JAX-RPC web services using Rational tolling.
You should have a beginner to intermediate level knowledge on EJB 3.0 and web services.
To complete the steps in this tutorial, you need:
- Rational Software Architect 7.5 and above
- Websphere Application Server 7.0
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"
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.
- To create a JAX-WS web service, add an annotation
@WebServicejust above the @Stateless anotation in the
DateFormatServicebean. Building the project creates a service under services.
Figure 1. DateFormatService bean
- 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.
Figure 2. Create router project
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.
Figure 3. Web Service EJB identity
- 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
- 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.
Figure 4. Web Service Explorer
- Provide the input date and click on Go button.
Figure 5. Invoke operation
|Sample code for this tutorial||Sample_code_DateFormatter.zip||7KB|
- "Web services hints and tips: JAX-RPC versus JAX-WS, Part 1" (developerWorks, Oct 2006) introduces a series that compares these two Java web services programming models.
- "Web services hints and tips: JAX-RPC versus JAX-WS, Part 2" (developerWorks, Nov 2006) compares the data mappings of these two web services specifications.
- "Design and develop JAX-WS 2.0 web services" (developerWorks, Sept 2007) walks you through how to do all of this and more by developing a sample order-processing application that exposes its functionality as web services. After going through this tutorial, you'll be able to apply these concepts and your newly acquired knowledge to develop web services for your application using JAX-WS technology.
Dig deeper into SOA and web services on developerWorks
Get samples, articles, product docs, and community resources to help build, deploy, and manage your cloud apps.
Keep up with the best and latest technical info to help you tackle your development challenges.
Software development in the cloud. Register today to create a project.
Evaluate IBM software and solutions, and transform challenges into opportunities.