IBM Support

Example of Creating a Web Service from an RPGLE Service Program using the IWS Server Wizard

Troubleshooting


Problem

This document depicts an example of creating a Web service from an RPGLE service program using the IWS Web Service Wizard.

Resolving The Problem

This document depicts an example of creating a Web service from an RPGLE service program using the IWS Web Service Wizard.

Here is the RPGLE service program that will be used for this example. You should store it in the library WEBTEST1 and the source physical file QRPGLESRC. Also, you should create the directory /home/WebTest1/Converts in the IFS.

    • - RPG Code


         
      Example
       
      H Nomain
            //Prototypes
           D FeetToInches    PR                  extproc('feettoinches')
           D  Feet                         10P 0
           D  Inches                       10P 0

           D CentsToDollars  PR                  extproc('centstodollars')
           D   Cents                       10P 0
           D   Dollars                     10P 2

            //********************************************************
            //** FeetToInches Procedure
            //** Converts Feet to Inches.
            //********************************************************
           P FeetToInches    B                   EXPORT

           D FeetToInches    PI
           D  Feet                         10P 0
           D  Inches                       10P 0

            /Free

             Inches = 12 * Feet;
             Return;

            /End-Free

           P FeetToInches    E

            //********************************************************
            //** CentsToDollars Procedure
            //** Converts Cents to Dollars.
            //********************************************************

           P CentsToDollars  B                   EXPORT

           D CentsToDollars  PI
           D  Cents                        10P 0
           D  Dollars                      10P 2
            /Free

             Dollars = Cents / 100;
             Return;

            /End-Free

           P CentsToDollars  E 



    First, the service program must be compiled and the PCML must be generated. For the purpose of this document, the PCML has been generated to an external file in the IFS. You should compile the source using the following commands:

    CRTRPGMOD MODULE(WEBTEST1/CONVERTS) PGMINFO(*PCML) INFOSTMF('/home/WebTest1/Converts/converts.pcml')
    CRTSRVPGM SRVPGM(WEBTEST1/CONVERTS) EXPORT(*ALL)

    You begin by loading IBM Web Administration for i. In a Web browser, go to http://<system name>:2001/HTTPAdmin. On the All Servers tab under Manage, select Create Web Services Server.

    Picture of IBM Web Administration for i

    This will take you through an eight-step process that will create the Web service from the RPGLE service program.

    For the first step, it will ask for the user ID that the server's jobs will run under. The default user ID is fine here. Select Use default user ID, and click Next.

    Picture of Step 1 - Specify User ID for Server
    For the second step, it confirms that you would like to deploy a new service to externalize an IBM i program. Make sure the checkbox is checked and click Next.

    Picture of Step 2 - Externalize an IBM i Program as a web service

    For the third step, it asks for the library and object names. Enter the library WEBTEST1 and the object CONVERTS. Because it is a service program, select the *SRVPGM and click Next.

    Picture of Step 3 - Deploy New service: Specify Location of IBM i Program Object
    If the program object does not have the PCML stored in it, you will need to specify the location of the PCML file. We compiled with the PCML file being output to the IFS, so we will specify that location here. Enter the path and name of the pcml file, which is /home/WebTest1/Converts/converts.pcml. You can also browse to find this file. Click Next.


    Picture of Step 3 - Specify Path of PCML file
    The fourth step asks for the name that you would like to give the service. You can also give it a description here. For the purpose of this example. we will name the service CONVERTS.

    Picture of Step 4 - Specify Name for Service

    In the fifth step, it lists the procedures and parameters that will be externalized as Web services. Select both centstodollars and feettoinches. In the Usage column, make sure that CENTS and FEET are set to be input parameters and DOLLARS and INCHES are set to be output parameters. Click Next.

    Picture of Step 5 - Select Export Procedures to Externalize

    For Step 6, it will ask for the user ID that will execute the RPG functions. You may specify the server ID or an existing ID. Click Next.

    Picture of Step 6 - Specify User ID for this Service

    In Step 7, the wizard sets up the library list for the Web service. Make sure WEBTEST1 is added to this list. Click Next.

    Picture of Step 7 - Specify Library List
    Step 8 is a summary page. Once you have reviewed this page, click Finish. This will complete the wizard and create the Web services server and the service that will run on it.

    Picture of Step 8 - Summary

    Once the server and service are created, they will be available for use. You can check on their status in IBM Web Administration for i.


    Picture of Manage Web Services Server Page


    To test the Web service, you can select Manage Web Services Server. This will show the deployed Web services on this server.

    Picture of Deployed Web Services

    By selecting Manage Deployed Services, you can see the full list of services on the server. Here, you can start, stop, deploy, and uninstall the Web services on this server. We can also test a Web service here using a generated test client. Choose CONVERTS and click Test Service.

    Picture of Manage Deployed Services Page

    This will bring up a test client screen. Here, you can add parameters, enter data, and test the different functions of the service.

    Picture of i5/OS Web Services Test Client
    The service is now ready to be accessed by an external Web service client.

    [{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"7.1.0"}]

    Historical Number

    538435538

    Document Information

    Modified date:
    18 December 2019

    UID

    nas8N1012707