Contents


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.

Prerequisites

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.

  1. 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
    Figure 1. Service Registry console
    Figure 1. Service Registry console
  2. Expand Service Documents and select Load Document.
  3. On the Load Document page, shown in Figure 2, do the following:
    • Select Remote file location.
    • Type http://saintbook.org/MightyMaxims/MightyMaxims.asmx?WSDL in 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 2. Load WSDL document
    Figure 2. Load WSDL document
  4. 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
    Figure 3. WSDL document upload status
    Figure 3. WSDL document upload status
  5. 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
    Figure 4. Custom properties of the           WSDL document
    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.

  1. Open Application Developer by selecting Start => Programs => IBM Software Development Platform => IBM Rational Application Developer => IBM Rational Application Developer.
  2. From the development workspace, select Windows => Preferences => Service Registry => WSRR Locations.
  3. In the WSRR Locations dialog, click Add to configure a new Service Registry location, as shown in Figure 5.
    Figure 5. WSRR Locations dialog
    Figure 5. WSRR Locations dialog
    Figure 5. WSRR Locations dialog
  4. In the Add Service Registry Preferences dialog, enter the following values, as shown in Figure 6, and click OK.
    • Alias: WSRR6.0.0.2
    • Host: localhost
    • Port: <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
    Figure 6. Add Service Registry           Preferences
    Figure 6. Add Service Registry Preferences
  5. The WSRR Locations dialog displays the new entry, as shown in Figure 7.
    Figure 7. WSRR location entry
    Figure 7. WSRR location entry
    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.

  1. 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 8. Show View dialog
  2. Figure 9 shows the Service Registry view in the Web perspective.
    Figure 9. Service Registry view
    Figure 9. Service Registry view
    Figure 9. Service Registry view
  3. Right-click WSDL Documents in the Service Registry view and select Retrieve WSDLs, as shown in Figure 10.
    Figure 10. Retrieve WSDLs
    Figure 10. Retrieve WSDLs
    Figure 10. Retrieve WSDLs
  4. 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
    Figure 11. Retrieved WSDL documents
    Figure 11. Retrieved WSDL documents
  5. 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
    Figure 12. MightyMaxims WSDL document
    Figure 12. MightyMaxims WSDL document

Import the WSDL document

To import MightyMaxims.asmx?WSDL into the dynamic Web project, SampleClient, do the following:

  1. 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
    Figure 13. Import           WSDL document
    Figure 13. Import WSDL document
  2. 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.wsdl as the File Name and check Generate folder structure, then click Finish,
    Figure 14. Import WSRR Document dialog
    Figure 14. Import WSRR Document           dialog
    Figure 14. Import WSRR Document dialog
  3. 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 15.
    Figure 15. WSDL editor
    Figure 15. WSDL editor
    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.

  1. 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.
  2. In the WSDL Binding Details dialog, select ForToday, as shown in Figure 16.
    Figure 16. Web Services Explorer
    Figure 16. Web Services Explorer
    Figure 16. Web Services Explorer
  3. In the Invoke a WSDL Operation dialog, click Go to execute the ForToday operation. The response will be displayed in the Status frame, as shown in Figure 17.
  4. 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
    Figure 17. Invoke a WSDL operation
    Figure 17. Invoke a WSDL operation
  5. The SOAP request and response envelopes are displayed, as shown in Figure 18.
    Figure 18. SOAP request and response envelopes
    Figure 18. SOAP request and response           envelopes
    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.

  1. 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.
  2. In the Web Services dialog, shown in Figure 19, verify that the Service definition field points to /SampleClient/WebContent/WEB-INF/saintbook.org/MightyMaxims/MightyMaxims.wsdl and that Java Proxy is selected in the Client type field, then click Next to proceed.
    Figure 19. Web Service Client dialog
    Figure 19. Web           Service Client dialog
    Figure 19. Web Service Client dialog
  3. 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.
  4. Click Yes to All when prompted to enable automatic file overwriting of the Web deployment descriptor /SampleClient/WebContent/WEB-INF/web.xml.
    Figure 20. Web Service Proxy Page
    Figure 20. Web Service Proxy Page
    Figure 20. Web Service Proxy Page
  5. To verify that the proxy class was generated successfully, navigate to SampleClient/JavaResources/com.TheQuoteForToday.www/MaximSoapProxy.java in the Project Explorer view, as shown in Figure 21.
    Figure 21. Java bean proxy
    Figure 21. Java bean proxy
    Figure 21. Java bean proxy

Generate the sample JSP client

To generate the client, do the following:

  1. Right-click SampleClient/JavaResources/com.TheQuoteForToday.www/MaximSoapProxy.java in the Project Explorer view and select Web Services => Generate Sample JSPs.
  2. 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
    Figure 23. Generate Web Service Client
    Figure 23. Generate Web Service Client
  3. 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
    Figure 23. Web Services Test Client
    Figure 23. Web Services Test Client

Summary

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.


Downloadable resources


Related topics

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Business process management, WebSphere, SOA and web services, Rational, DevOps
ArticleID=291932
ArticleTitle=Generate a Web service client using Rational Application Developer and WebSphere Service Registry and Repository
publish-date=03052008