Sample: Create and test an iSeries Web service

This example illustrates how to create and test an iSeries Web service from a service program procedure.

Time required

Allow 15 minutes to run the example with the supplied data and to review the output.

Before you begin

The sample entitled Sample: Call an iSeries service program procedure from a Java application is a prerequisite for this sample.

This example shows you how to create and test an iSeries Web service from a service program procedure using the Program Call and Web Services wizards. The service program used in this example is the same as in the prerequisite example. Since we have already created the PCML file in that example, we can retrieve the data from it.

  1. Open a Web perspective.
  2. To create a Web service, you need a Web project. Right-click anywhere in the Navigator view and select Dynamic Web Project. Enter the name WebProject as the project name and click Finish.

Now use the Program Call wizard to create the Java bean:

  1. In the Project Explorer view, under Dynamic Web Projects, select WebProject.
  2. Click the Create Program Call Bean icon Create Program Call bean icon (picture of server) in the workbench menu bar. This launches the Program Call wizard.
  3. Click Import. In the Select PCML file from field, select Workspace.
  4. In the left pane, double-click JavaProject. In the right pane, click QueryProductCost.pcml. Click OK. In the left pane, select QueryProductCost. Click OK.
  5. The first page of the Program Call Wizard now contains the program call definitions from the first sample. Click Next to proceed to the next page.
  6. If the Folder field is not already filled in, click Browse, expand WebProject, then select JavaSource. Click OK.
  7. Enter query.product in the package field.
  8. The Services check box should be already selected.
  9. Click Next. Enter the same Authentication and Library list settings you used in the first sample.
  10. Click Finish. You should find these files created for you.
    • In the Java Resources/JavaSource folder of WebProject:
      • defaultPCW.config
      Note: The JavaSource folder is called Java Resources when you are looking at a Web project in the Web perspective.
    • In the Java Resources/JavaSource/query.product folder of WebProject:
      • QueryProductCostInput.java
      • QueryProductCostServices.java
      • QueryProductCostResult.java
      • QueryProductCost.pcml
    • In the root of WebProject:
      • QueryProductCost.mpcml
    • In the WebContent/WEB-INF/lib folder:
      • iwdtrt.jar
      • jt400.jar
      • recjava.jar
      • eablib.jar
      • ccf.jar

QueryProductCostServices.java is the Java bean that can be used by the Web Services wizard to create a Web service for you. For every program that you define in the Program Call wizard, two methods are generated. You can use either of the methods to get the data returned from the remote program call. For example, these methods are generated in QueryProductCostServices.java:

The first method returns the output data in XML format. The Web services client can retrieve the data by parsing the XML string, such as this sample XML string:

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<QueryProductCost>
<price>29.95</price>
</QueryProductCost>

The second method returns the output data in a class called QueryProductCostResult.java. The Web services client can retrieve data using the getter methods from the class.

Now you can use the Web Services wizard to create a Web service from the classes created by the Program Call wizard.

  1. Right-click QueryProductCostServices.java.
  2. Select New > Other > Web Services > Web Service. Click Next. (You might have to select the Show all wizards check box.)
  3. On the Web Services page, Web service type should be pre-filled with Java bean Web Service. Select Generate a proxy. Select Test the Web service. Click Next.
  4. On the Object Selection page, the Bean field should be pre-filled with query.product.QueryProductCostServices. If not, browse to the JavaSource/query/product folder and select QueryProductCostServices.java. This specifies the Java bean from which the wizard will create the Web service. Click OK. Click Next.
  5. On the Service Deployment Configuration page, make sure the Service Project is set to WebProject. The Service project EAR should be set to DefaultEAR. Change the default entry in the Client project EAR field to something different, for instance TestDefaultEAR. Click Next.
  6. On the Web Service Java Bean Identity page, click Deselect All, then select only queryproductcost_XML(QueryProductCostInput) and queryproductcost(query.product.QueryProductCostInput). Click Next.
  7. On the Web Service Proxy Page, click Next, accepting defaults.
  8. On the Web Service Client Test page, make sure Test the Generated proxy and Run test on Server are selected. Click Finish. The Web browser is launched and the WebSphere test environment executes TestClient.jsp, a sample test client that the Web Services wizard creates to test the Web service.
  9. Select queryproductcost_XML in the left frame of the Web browser.
  10. Enter 1 in the item field. Click Invoke. The following is displayed in the Result frame:
    <?xml version="1.0" encoding="UTF-8"?> <QueryProductCost> <price>29.95</price> </QueryProductCost>

You have successfully created a Web service and run it in the WebSphere test environment.

Related tasks
Calling an iSeries program from your Java application
Creating a Web service from an iSeries program or service program procedure
Developing Web services
Creating a Web service from a Java bean using the IBM SOAP runtime environment
Related reference
Installing the sample libraries