Creating the RPG service program

You want your application to retrieve the price of an item, given the item number. This is handled by an RPG service program that contains a procedure called QryProdCost. The WHOLESALE library contains an RPG service program named CWWSSRV. This program contains a QryProdCost procedure that can take the item numbers as input, open the Inventory file within the WHOLESALE library, retrieve the price from the inventory database, and return the price. To accommodate this task, the interface has two parameters, one for the item number, and the other for the price. If the item number or price is not found, the RPG program returns a message to the interface.

To create this Web service, you first create a Java bean with the Program Call wizard, to invoke the QryProdCost RPG procedure. Then, you use Web services to enable the RPG procedure as a Web service through the Java bean.

To create the Java bean:

  1. In the Web perspective, right-click Project514 and select New > Other.
  2. Select iSeries > Java from the left pane of the window and then select Program Call Bean on the right pane.
  3. Click Next to invoke the Program Call wizard.
  4. In the Java bean name field, underneath the Add Program title, enter Inventory.
  5. In the Program object field, enter CWWSSRV, the name of the RPG service program.
  6. In the Library field, enter WHOLESALE.
  7. From the Program type drop-down list, select *SRVPGM.
  8. In the Entry point field, enter QryProdCost.
  9. Click OK to add the program definition.

Creating the parameters and generating the Java bean

Now that you have specified the program, you can add parameters. The CWWSSRV RPG program contains the following two parameters:

To add the item number parameter:

  1. In the left panel of the Program Call wizard, click the Inventory program call definition to select it. This action re-populates the fields on the right side of the page.
  2. Click Add Parameter.
  3. In the Parameter name field, enter itemno.
  4. From the Data type drop-down list, select packed decimal.
  5. In the Length field, enter 5.
  6. In the Precision field, enter 0.
  7. From the Usage drop-down list, select input.
  8. Click OK to add this parameter. In the left pane, note that itemno appears beneath Inventory. Now you are ready to add the second parameter.

To enter the item cost parameter:

  1. In the left panel of the Program Call wizard, click the Inventory program call definition again to select it. This action re-populates the fields on the right side of the page.
  2. Click Add Parameter.
  3. In the Parameter name field, enter cost.
  4. From the Data type drop-down list, select packed decimal.
  5. In the Length field, enter 7.
  6. In the Precision field, enter 2.
  7. From the Usage drop-down list, select output.
  8. Click OK to add this parameter. In the left pane, notice that cost appears beneath Inventory. At this point, the wizard should look like this. Note that the icon to the left of the a parameter shows if it is of type input, input & output, or output:
    This screen capture shows the Program Call wizard with the itemno and cost parameters underneath Inventory.

To define the package name for these parameters, in the Program Call Wizard,

  1. Click Next.
  2. In the Package field, enter scenario as a package name. Leave the defaults in the other fields.
  3. Clear the Java Application check box.
    Note:
    Review the list of files under "These files will be generated by the wizard" and note that the name of the generated Java bean will be InventoryServices.java.
  4. Click Finish to generate the files.

Making a Web service from the Java bean

After creating the Java bean that invokes the RPG program, the next step is to convert the bean into a Web service so that other programs can access the same RPG program over the Internet.

When creating the Web service, a Web Services wizard generates the WSDL files that are distributed to users who need to use the Web Service. To create the service:

  1. In the Navigator view of the Web perspective, expand Project514 > Java Source > scenario.
  2. Right-click InventoryServices.java and select New > Other.
  3. In the New window, click Web Services, click Web Service on the right side of the window, and then click Next.
  4. Select the Generate a proxy and the Test the generated proxy check boxes.
  5. Click Next three times and notice the generation of the necessary files. When you get to the Web Service Java Bean Identity window, click Finish. You might need to click Finish a second time if you see any errors. If you are not able to finish the wizard, just click Cancel and most of the necessary files will be created anyway.


[ Top of Page | Previous Page | Next Page | Table of Contents ]