Web services has been called the next holy grail for component reuse and language interoperability. With the release of IBM WebSphere® Studio Application Developer (Application Developer), developers have a much easier and faster way to build Web services.
This article shows you one of the Application Developer tools that can help you build the JavaTM client functionality used to invoke a Web service. It also gives you a simple demonstration of the power of Web services by invoking a Delphi e-mail service using a Java client.
Finding a Web service to consume
You've probably heard of Universal Description, Discovery, and Integration (UDDI) repositories that can store information about a business and the Web services that the business offers. There is, however, another way of publishing a Web service for consumption. A Web services portal is a Web site that lets Web service providers publish their Web services for consumption.
In this article, we'll access the Web services portal XMethods, search for a Web service, and invoke it from a Java client. XMethods is a free public resource that lets Web service providers publish their Web service information for consumption, and provides a central location for Web service consumers. (The XMethods site is for testing only and is not supported for production use.) XMethods offers Web services with various functions and implementation languages such as Microsoft® SOAP, Apache SOAP, GLUE, and Delphi. If you search the XMethods site for "email" (no hyphen), you'll find a Web service called "Send an Email" that provides basic e-mail functionality and is implemented in Delphi. Clicking on the name takes you to an information page that provides all the information that you need to invoke the Web service, including name, publisher, toolkit, and a link to the Web Services Description Language (WSDL) file.
Downloading and importing the WSDL file
WSDL is a common framework for describing the tasks performed by a Web service. In order to use the e-mail Web service, you need to download its WSDL file and save it on your machine. Some Web browsers may save the WSDL file as an XML file -- if that happens, change the file extension to WSDL. Next, in order to use the WSDL to create a Web service client, import the file into an existing Web project in Application Developer:
- In your Web project, create a folder named
wsdlunderneath thewebApplicationfolder. - Select File => Import. From the Import dialog box, select File system.
- Navigate to the WSDL file and click Finish. The WSDL file will be imported into the Web project.
Running the Web service client wizard
Application Developer provides a wizard that generates client proxies and a sample application for invoking Web services. We will use the wizard to create all the code that is required to invoke the Web service. To do this, follow the steps below.
- Select the WSDL file within the Web project. Select File => New.
- In the New dialog box, select Other. Select Web Services from
the left panel and Web Service Client from the right panel. Click Next.
The Web Service Client dialog box will open, as shown in Figure 1 below.
Figure 1.
- The Web Service Client dialog box gives you a selection of options when
creating the client functionality. First, make sure that the correct Web project
has been selected.
- We will get Application Developer to generate the proxy classes and a sample
application to run the Web service. Click the Generate a proxy, Generate
a sample, and Launch the sample check boxes. Then click Next.
The Web Service Client wizard prompts for the WSDL file. This enables the
wizard to generate the proxy and sample code required to invoke the Web service.
- Click Next. The wizard reads the WSDL file and lists the available
services, including the parameters required and the response objects sent
back to the client. Keep the default functionality offered and click Next,
Next again, and then Finish.
The wizard generates the required proxy classes and sample application. Application Developer then publishes the application to the internal WebSphere Application Server and launches it. If successful, you will see Application Developer swap to the Server perspective and display the sample application input Web page.
- Select the SendEmail URL located on the Methods frame, as shown in
Figure 2 below.
Figure 2.
- When reading the WSDL file, Application Developer identifies the four parameters
required to invoke the Web service. The Web page above contains text boxes
for the four parameters, and the next step is to enter data into them. When
the application is invoked, an e-mail will be sent to the address you enter
in the ToAddress text box.
- Enter a valid recipient e-mail address in the ToAddress text box. Enter
your e-mail address in the FromAddress text box. Enter in a brief subject
and message in the ASubject and MsgBody text boxes. After entering the data,
click Invoke.
- The sample application will then invoke the Web service via the proxy classes
generated. If the invocation is successful, the Web service will return a
0, and you will see the result of the invocation in the Result frame of the
Web page.
- Check the recipient's e-mail account! It should contain an e-mail sent by the Web service.
We have used a Web service within a Java application to send an e-mail with a brief message. We used Application Developer to generate the Java proxies required to invoke the Web service. The proxy classes can be reused in any project that wants to use this Web service. Application Developer also generated a sample application that let us invoke the Web service. Notice that the Web service is implemented in Delphi, but we have no idea (nor do we care) where the Web service is located or what operating system it is running on! If you want to, you can export the sample application as a WAR or EAR file, upload it to WebSphere Application Server 4.0, and ask other people to test the functionality.
A future article will show you how to convert existing Java
functionality into a Web service, deploy to an application server, and enable
it for consumption by other applications.
Web services is still young, and standards such as WSDL, UDDI, and SOAP are
still being standardized. Organizations and committees such as W3C, the Java
Community Process (JCA), and the Web Services Interoperability Organization
(WS-I) are working to provide standards and interoperability across vendors.
The next question you may ask is how could you charge for this service and how
could you rate it in regards to Quality of Service (QoS)? IBM has introduced
the Web Services Hosting Technology toolkit, a technology preview that you can
download from IBM alphaWorks. It
lets Web service providers rate their Web services for QoS, and define offers
for Web services. Customers can register with the run-time functionality, and
choose Web service offers that they want to use. The toolkit also provides a
lightweight invoice system that demonstrates how you can bill users for using
your Web service.
- Web Services Interoperability Organization
(WS-I) -- An open industry organization chartered to promote Web services
interoperability across platforms, operating systems, and programming languages.
- IBM developerWorks
Web services zone -- Your central resource for information, tools, code,
articles, and best practices for Web services developers and architects.
- Web
services products inventory -- A descriptive inventory of over 100 currently
available Web services products from a wide range of software providers.
Marc Krisjanous is part of the IBM Australia/New Zealand WebSphere Technical team in Melbourne, Australia. He specializes in WebSphere Application Server, WebSphere Edge Server, and associated development tools such as WebSphere Studio Application Developer. Marc has worked on various e-business projects in the IT industry for six years. You can reach Marc at marckris@au1.ibm.com .




