Generate a Web service client using Rational Application Developer and WebSphere Service Registry and Repository
WebSphere Service Registry and Repository (hereafter called Service Registry) is a central repository for the querying and managing of reusable service documents, including Web Services Description Language (WSDL), Service Component Definition Language (SCDL), Extensible Markup Language (XML), and XML Schema Definition (XSD) document types. With Service Registry, you can easily query these documents and use them as building blocks for new composite applications. With the Service Registry Eclipse plug-in, you can query Service Registry for a WSDL document, then import the document into an existing Web project in order to create a client to consume the Web service as described in the WSDL document.
From a tools perspective, we’ll use the Eclipse-based Rational Application Developer for WebSphere Software V7 (hereafter called Application Developer), to generate a JavaServer Pages (JSP) Web application client to consume the public Web service. Application Developer includes plug-ins and wizards for a variety of development roles, such as Java™ programmers, and database, J2EE and Web Services developers.
In order to complete the steps in this article, you must meet the following prerequisites:
- Install Application Developer in a Windows operating environment.
- Install Service Registry V6 (local to the Application Developer installation).
- Install Service Registry Eclipse plug-in SA02.
- Create an enterprise application project called SampleEAR, consisting of a dynamic Web project called SampleClient.
- Install the WebSphere Application Server (hereafter called Application Server) V6.1 Test Environment.
- Ensure that you have internet connectivity.
Load the WSDL document
First you need to publish the WSDL document describing the public Web service MightyMaxims to Service Registry. This Web service, available at www.xmethods.net, returns a random quote upon invocation.
First, start Service Registry from the WebSphere administrative console, by selecting Applications => Enterprise Applications => ServiceRegistry.
- Open the Service Registry console, shown in Figure 1, by pointing your browser to
http://localhost:<embedded HTTP port>/ServiceRegistry.Note: To get
the <embedded HTTP port>, in the WebSphere administrative console, select Servers => Application Servers
=> server1 => Ports => WC_defaulthost.
Figure 1. Service Registry console
- Expand Service Documents and select Load Document.
- On the Load Document page, shown in Figure 2, do the following:
- Select Remote file location.
http://saintbook.org/MightyMaxims/MightyMaxims.asmx?WSDLin the Remote file location field.
- Select WSDL as the document type.
- Enter a document description and a version, then click OK.
Figure 2. Load WSDL document
- Figure 3 shows that the WSDL document was successfully uploaded to Service
Registry. Verify the description and version of the document.
Figure 3. WSDL document upload status
- Select Custom properties (under Additional properties on the
right) to view the metadata properties of the
WSDL document, as shown in Figure 4.
Figure 4. Custom properties of the WSDL document
Configure the Service Registry Eclipse plug-in
Next you need to configure the Service Registry Eclipse plug-in (SA02) in Application Developer. SA02 enables you to upload, query and edit service documents from an Eclipse environment. After the plug-in is installed, the Service Registry view is added to your development workspace with service documents categorized into Concepts (GenericObject), WSDL, XML and XSD.
- Open Application Developer by selecting Start => Programs => IBM Software Development Platform => IBM Rational Application Developer => IBM Rational Application Developer.
- From the development workspace, select Windows => Preferences => Service Registry => WSRR Locations.
- In the WSRR Locations dialog, click Add to configure a new
Service Registry location, as shown in Figure 5.
Figure 5. WSRR Locations dialog
- In the Add Service Registry Preferences dialog, enter the
following values, as shown in Figure 6, and click OK.
<RMI connector port>. To get the <RMI connector port>, in the WebSphere administrative console, select Servers => Application Servers => server1 => Ports => BOOTSTRAP_ADDRESS.
- Security: none
Figure 6. Add Service Registry Preferences
- The WSRR Locations dialog displays
the new entry, as shown in Figure 7.
Figure 7. WSRR location entry
Retrieve the WSDL document
In this section, you'll query the uploaded WSDL document from the System Registry view. You'll perform a wildcard query that returns all WSDL documents uploaded to Service Registry. To limit the search criteria, you can filter results based on document type, namespace, version and metadata.
- Open the System Registry view, by selecting Window => Show
View => Other, then double-clicking Service Registry
under the Service Registry folder in the Show View dialog, as shown in Figure 8.
Figure 8. Show View dialog
- Figure 9 shows the Service Registry view in the Web
Figure 9. Service Registry view
- Right-click WSDL Documents in the Service
Registry view and select Retrieve WSDLs, as shown in Figure 10.
Figure 10. Retrieve WSDLs
- The Retrieved Items dialog, shown in Figure 11, displays the query
results for WSDL documents uploaded to Service Registry. Verify that the
appropriate service document is retrieved and click OK.
Figure 11. Retrieved WSDL documents
- In the Service Registry view, you'll see the MightyMaxims.asmx?WSDL
document listed under WSDL Documents, as shown in Figure 12.
Figure 12. MightyMaxims WSDL document
Import the WSDL document
To import MightyMaxims.asmx?WSDL into the dynamic Web project, SampleClient, do the following:
- Right-click MightyMaxims.asmx?WSDL under
WSDL Documents in the Service Registry view, and
select Import Document, as shown in Figure 13.
Figure 13. Import WSDL document
- In the Import WSRR Document dialog, shown in Figure 14, expand the
SampleClient project and select the WEB-INF folder. The
Enter or select the parent folder field will be automatically filled in
with SampleClient/WebContent/WEB-INF. Enter
MightyMaxims.wsdlas the File Name and check Generate folder structure, then click Finish,
Figure 14. Import WSRR Document dialog
- To verify that the WSDL document was imported successfully, navigate to
SampleClient/WebContent/WEB-INF/saintbook.org/MightyMaxims in the
Project Explorer view and double-click MightyMaxims.wsdl to launch it
in the WSDL editor, as shown in Figure
Figure 15. WSDL editor
Test the WSDL document
You can use the Eclipse Web Services Explorer to verify that the exposed function is working as expected and to view the SOAP request and response envelopes.
- Open Web Services Explorer by right-clicking SampleClient/WebContent/WEB-INF/saintbook.org/MightyMaxims/MightyMaxims.wsdl in the Project Explorer view and selecting Web Services => Test with Web Services Explorer.
- In the WSDL Binding
Details dialog, select ForToday, as shown in Figure 16.
Figure 16. Web Services Explorer
- In the Invoke a WSDL Operation dialog, click Go to execute the
ForTodayoperation. The response will be displayed in the Status frame, as shown in Figure 17.
- To view the SOAP request and response envelopes, click Source
in the top right corner of the Status frame.
Figure 17. Invoke a WSDL operation
- The SOAP request and response envelopes are displayed, as shown in Figure 18.
Figure 18. SOAP request and response envelopes
Generate the Web service client proxy
Now you need to generate the proxy class to be used by the sample JSP Web application as an intermediary layer to invoking the Web service. Without the Java bean proxy, you won't be able to generate the sample JSP Web application.
- To open the Web Service Client wizard, right-click the SampleClient/WebContent/WEB-INF/saintbook.org/MightyMaxims/MightyMaxims.wsdl document in the Project Explorer view and select Web Services => Generate Client.
- In the Web Services dialog, shown in Figure 19, verify that the Service definition field points to
and that Java Proxy is selected in the Client type field, then click Next to proceed.
Figure 19. Web Service Client dialog
- In the Web Service Proxy Page dialog, shown in Figure 20, verify that the Output folder field points to /SampleClient/src and that no security is selected in the Security configuration field, then click Finish.
- Click Yes to All when prompted to enable automatic file
overwriting of the Web deployment descriptor
Figure 20. Web Service Proxy Page
- To verify that the proxy class was generated successfully, navigate to
in the Project Explorer view, as shown in Figure 21.
Figure 21. Java bean proxy
Generate the sample JSP client
To generate the client, do the following:
- Right-click SampleClient/JavaResources/com.TheQuoteForToday.www/MaximSoapProxy.java in the Project Explorer view and select Web Services => Generate Sample JSPs.
- In the Web Service Client Test
dialog, verify that the appropriate values are selected, as shown in Figure 22,
then click Finish.
Figure 22. Generate Web Service Client
- The Web Services Test Client application is launched in the configured
browser. Click forToday() in the Methods frame, then click Invoke
in the Inputs frame. A response displays in in the Result frame,
as shown in Figure 23.
Figure 23. Web Services Test Client
In this article, you learned how to upload a public WSDL document to Service Registry, then import the document into a Web project in Application Developer using the Service Registry Eclipse plug-in. Finally, you generated a Web service proxy class and a sample JSP client to consume the Web service.
- developerWorks WebSphere BPM zone: Get the latest technical resources for WebSphere BPM solutions, including articles, tutorials, events, downloads and more.
- WebSphere Service Registry and Repository V6.0 Information Center: Get complete product documentation for Service Registry.
- Managing services using the Eclipse user interface: This topic describes how to use the Eclipse UI to access documents in Service Registry.