This example illustrates how to create and test an iSeries Web
service from a service program procedure.
Allow 15 minutes to run the example with the supplied data and to review
the output.
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.
- Open a Web perspective.
- 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:
- In the Project Explorer view, under Dynamic Web Projects, select WebProject.
- Click the Create Program Call Bean icon
in the workbench menu bar. This launches
the Program Call wizard.
- Click Import. In the Select PCML file
from field, select Workspace.
- In the left pane, double-click JavaProject. In
the right pane, click QueryProductCost.pcml. Click OK.
In the left pane, select QueryProductCost. Click OK.
- 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.
- If the Folder field is not already filled in, click Browse,
expand WebProject, then select JavaSource.
Click OK.
- Enter query.product in the package field.
- The Services check box should be already selected.
- Click Next. Enter the same Authentication and Library
list settings you used in the first sample.
- Click Finish. You should find these files created
for you.
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:
- public String queryproductcost_XML(QueryProductCostInput inputData)
- public QueryProductCostResult queryproductcost(BigDecimal item)
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.
- Right-click QueryProductCostServices.java.
- Select .
Click Next. (You might have to select the Show
all wizards check box.)
- 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.
- 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.
- 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.
- On the Web Service Java Bean Identity page, click Deselect
All, then select only queryproductcost_XML(QueryProductCostInput)
and queryproductcost(query.product.QueryProductCostInput). Click Next.
- On the Web Service Proxy Page, click Next, accepting
defaults.
- 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.
- Select queryproductcost_XML in the left frame of
the Web browser.
- 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.