By: Andi Gutmans, Sam Pinkhasov, and Cal Evans.
As is the case with most development teams tasked with maintaining legacy applications, most System i shops continue to maintain valuable data that is trapped within their legacy applications. In most cases, these applications are not easily integrated with outsides applications or services. However, System i developers now have a new tool in their toolbox, PHP. PHP provides the tools System i developers need to easily expose their data and services to external applications via Web Services. Utilizing PHP and Zend’s developer tools, Web Services can easily be written to wrap existing programs.
Zend provides a complete set of products that support System i integration from development to production. Zend’s solutions include native System i database support and System i objects access. (e.g., RPG/COBOL/CL programs, CL commands, spooled file entries, data area and many more).
In this article we will show how quick and simple it is to create a Web Service wrapper for an existing RPG program.
So exactly what is a web service? Wikipedia tells us this.
The W3C defines a Web service as a software system designed to support interoperable machine-to-machine interaction over a network. Web services are frequently just application programming interfaces (API) that can be accessed over a network, such as the Internet, and executed on a remote system hosting the requested services.
A definition more germane to our discussion however, is this one.
A Web Service is a unit of application logic providing data and/or services to other applications.
Stripping away the tech-speak, a Web Service enables an application to expose what it does or what it knows so that other applications can make use of it.
An example of this would be, a company using legacy order entry program that exposes its core functionality as an API. The order entry program now becomes a Web Service exposing what it does to other applications. The corporate website’s process for collecting orders can now utilize that Web Service to insert new orders directly into the legacy application as they become available. Since Web Services are wrapped around the core business logic of the order entry program, new orders can be acted upon as if they were manually entered.
In short, Web Services delivers on the promise of process interoperability made by so many technologies before it. Web Services puts Service Oriented Architecture (SOA) easily within our grasp. PHP makes Web Services on System i easy.
Currently there are many Web Services available on the Internet. Each of them can be used to extend existing applications and give new functionality to the users. The web site www.programmableweb.com tracks publicly available APIs. It lists more than 400 APIs, ranging from mapping and address correction to data storage. Since some Web Services carry fees or access restrictions it is important to review the appropriate documentation before implementing to make sure there are no nasty surprises after you have deployed. The list of ways you can extend existing applications via web services grows on a daily basis and it limited only by the imagination. Web Services opens the door for software applications written in different languages to be able to exchange data and services.
Until recently, creating a new Web Service was not a trivial task. Building Web Services still requires knowledge of OOP, XML and SOAP. However Zend’s products shield developers from most of the complex details. Now building Web Services on System i has been greatly simplified. This allows developers to spend less time on the details of Web Services so they can spend their energy solving the business problem at hand. This would be a good point to stop and take a look at what goes into creating a Web Service using Zend’s tools that will wrap existing RPG program.
Creating a Web Service
Let’s see an example of how easy it is to create a simple Web Service that wraps an existing RPG program containing two parameters: a code number and a description name. The Web Service is to receive a code number as input parameter and will return a description name as the output parameter.
Zend Studio for i5/OS includes templates to help users build PHP applications quickly. The templates are available via a Code Completion pop-up menu.
#1: Start Zend Studio (click Start | Programs | Zend Studio for i5/OS | Zend Development Environment).
#2: Enter the following lines into Studio’s editor:
A pop-up containing a list of templates/functions will appear as soon as you begin to type (or click Ctrl + spacebar).
#3: Select i5ProgramServices.
This template is one of many templates included with Zend Studio for i5/OS. It includes all the code required to create a Web Service wrapper for an RPG program.
Zend Studio’s Editor uses its Code Completion pop-up to display template / function choices that begin (in this example – with the characters “i5”). After selecting the i5ProgramService Web Service template, the editor inserts the code that was pre-typed in the template. See the figure below.
#4: Use the TAB key to scroll through the program variables and edit them (as required). For our example, we need to stop the TAB key on the variables
#5: Next, specify the RPG program and library name that we want to call for this service. Move the TAB to
In order to call an RPG program containing additional parameters, simply uncomment the appropriate number of commented program parameters (included in the template) or type additional parameters as required.
#6: Next, save the code by clicking File | Save.
Now we need to create a WSDL file. WSDL files are XML format files used for describing networks services as a set of endpoints operating on messages containing either document-oriented or procedure oriented information.
Zend Studio for i5/OS provides a WSDL generator (Tools | WSDL Generator) that allows you to generate WSDL files by:
- Defining which files and classes are going to be extracted,
- Providing the URL of each class (mapped to a port)
- Configuring the global setting for WSDL files (name convention, binding options and encoding style).
Enter the required information and click Finish. This will create the WSDL file and open it in Zend Studio’s Editor. The figures below show the WSDL wizard dialogs:
Here is the WSDL file generated by the WSDL Generation Wizard.
Finally, we need to create a client program to call the service. The following code defines the WSDL file for the service.
$my_client = new SoapClient('zend.wsdl');
That’s it !
Zend Studio for i5/OS has made creating a Web Service a matter of a few simple steps.
In order to deploy, simply supply the WSDL file with the client program. We are now able to call an RPG program from any place in the world.
Web Services Benefits
The use of Web Services in System i positively impacts R&D by shortening the development cycle and cutting costs.
Because Web Services are re-usable, many common business routines can now be replaced by a single Web Service. This means that only one code entity needs to be maintained (i.e. the Web Service).
Web services are also building blocks of Service Oriented Architecture (SOA). In SOA, each service is a stand-alone block of business functionality which is loosely-coupled as well as being highly inter-operable. Examples of this could be services to:
- Verify an account number
- Validate customer payment
- Send eMails
- Synchronize/transfer data between systems
Web Service reusability can be applied to Composite Applications as well. New applications can now be created by using a set of Web Services to access legacy data and applications, adding new business rules to deliver a new solution.