You are on page 1of 14

Calling a Web Service from Oracle Application Server 10g Forms Services

Purpose

This module describes how to call a Web Service from Oracle Application Server 10g (OracleAS) Forms Services.
The web services referred to is unfortunately no longer available online. See the corresponding How-To for 10.1.2
for a working example.

Topics

This module discusses the following topics:

Overview
Calling a Web Service from Forms
Create a Web Service Stub
Call the Stub from a Forms Application
Sample code and more information

Viewing Screenshots

Place the cursor on this icon to display all screenshots. You can also place the cursor on each icon to see
only the screenshot associated with it.

Overview

Back to List of Topics

OracleAS Forms Services provides a comprehensive application framework to deploy enterprise-class applications
to the Internet with a rich Java interface. A key feature of Oracle Forms is that it provides a number of integration
points to allow Forms to communicate with other technologies.

One of the most popular technologies now emerging is Web services. A Web service can be used to encapsulate
any kind of business information, from an entire application to a simple service. Oracle Forms enables you to
easily integrate a Web service into an existing Forms application through the use of the Java Importer.

Prerequisites

Back to List of Topics

In order for this lesson to work successfully, you will need to have performed the following:

1. Install Oracle JDeveloper 9.0.4.

2. Install Forms Developer 9.0.4.

Calling a Web Service from Forms


Back to List of Topics

In order to call a Web service from a Forms application, you must complete two main steps:

Create a Web service stub (you can use Oracle JDeveloper to perform this step)
Call the stub from a Forms application

Create a Web Service Stub

Back to List of Steps

The first step is to create the Web service stub. In this example, you use a simple Web service available on the
Internet that provides currency conversion. The Web service is defined by its WSDL. You use Oracle JDeveloper
10g to create the Web service stub. This stub is a Java class that provides the interface to the Web service. Forms
calls the interface rather than invoking the Web service directly.

1. To create a new workspace and project, select File> New> General> Workspace and click
OK.

Name the directory and the workspace WebServiceWS. Be sure that Add a New Empty
Project is checked, then click OK.
Accept the default project name and click OK.

2. With the new project selected in JDeveloper, select File> New> General> Web Services>
Web Service Stub/Skeleton and then click OK. The Web Service Stub/Skeleton Wizard
displays.
3. If the Welcome screen appears, click Next to go to Step 1 of 2 in the Wizard. On this screen,
in the WSDL Document URL enter the URL that points to the WSDL of the Web service. For
this example, the URL is:
http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl

Click Next.

4. Step 2 of 2 in the Wizard displays. This shows the facilities available to be called on this Web
service. These should be selected by default. Click Finish.
5. JDeveloper automatically creates the code required to call the Web service. Save and Rebuild
the project.

5a. (Optional Step).When you run a Web service stub from within JDeveloper, the proxy settings
come from the IDE (Tools > Preferences > Web Browser/Proxy). Because you intend to
invoke the Web service stub from Forms, you may have to define the proxy settings in the
code. If you are using a proxy, then you must modify the CurrencyExchangeServiceStub
constructor.

Replace
m_httpConnection = new OracleSOAPHTTPConnection();

with
Properties prop = new Properties();
prop.setProperty(OracleSOAPHTTPConnection.PROXY_HOST, "myproxy");
prop.setProperty(OracleSOAPHTTPConnection.PROXY_PORT,"80");
m_httpConnection = new OracleSOAPHTTPConnection(prop);
Replace "myproxy" with the host name of your proxy server.

6. Although you have created only one class, that class relies on a number of other Java classes.
The next step is to package all the relevant files into a single JAR file.

Select File > New > General > Deployment Profiles > JAR File - Simple Archive and click
OK.
A dialog displays showing the name and location of the deployment descriptor. Accept the
defaults and click Save.

7. The JAR Deployment Profile Settings Dialog displays. Select Dependency Analyzer and
check the check box for Oracle SOAP. Click OK.
8. This creates a deployment node on in the system navigator. Select the node, right mouse click
and select Deploy to JAR File.

This saves the JAR file to disk. Note the full directory path and name of this JAR file. You will
need this information to set your CLASSPATH in the next step.
Call the Stub from a Forms Application

Back to List of Steps

For this part of the exercise you need a working installation of Forms.

Once you have created the Web service stub, the next step is to create a form to call the stub to invoke the Web
service. For this simple test case, you add a button that calls the Web service stub and returns (and messages out)
the rate of exchange. This functionality can be modified to fit the needs of your application.

1. Select Start > Settings > Control Panel.

Double-click on System, select the Advanced tab and click the Environment Variables
button (or just select the Environment tab on NT).

From the System Variables, select CLASSPATH and then click Edit (there is no Edit button
on NT).

Add the full directory name and name of the JAR file created in step 7 above.

Click OK (on NT, click Set, then OK) to dismiss the dialog.

2. The next step is to update the Forms environment file to indicate the location of the JAR file.
The Forms environment file is called default.env in a default installation.

Prepend the full directory path and JAR file name to the CLASSPATH entry.

For example:
CLASSPATH=
d:\jdev904\jdev\mywork\WebServiceWS\Project1\deploy\archive1.jar;D:\...
3. Start up Oracle Forms Developer and create a new form. Create a canvas and a non-base
table block.

4. Select Program > Import Java Classes and select the Java class created in JDeveloper.
Click Import. This creates a PL/SQL package for the CurrencyExchangeServiceStub Java
class.
5. Change the Import Classes field to java.lang.Float (just type this in) and click Options.
Check the boxes Include inherited methods/fields and Include get/set for public fields.
Click OK.

Click Import. This creates a PL/SQL package for the Float Java class. This is required
because the CurrencyExchangeServiceStub returns an object of type Float. This is not
native to Forms and so we also need to import the Float object.
6. Change the Import Classes field to java.lang.Exception (just type this in) and click Options.
Check the boxes Include inherited methods/fields and Include get/set for public fields.
Click OK.

Click Import. This creates a PL/SQL package for the Exception Java class. While this is not
essential, it does make error reporting easier.

Now click Close to dismiss the dialog.

7. Create a button on the canvas and define a When-Button-Pressed trigger with the following
code:
DECLARE
jo ora_java.jobject;
rv ora_java.jobject;
ex ora_java.jobject;
BEGIN
JO:= CurrencyExchangeServiceStub.new;
--
--This will get the exchange rate from US Dollars to UK Sterling.
--
RV:= CurrencyExchangeServiceStub.getRate(JO,'USA','UK');
message (float_.floatValue(RV));
EXCEPTION
WHEN ORA_JAVA.JAVA_ERROR then
message('Unable to call out to Java, ' ||ORA_JAVA.LAST_ERROR);
WHEN ORA_JAVA.EXCEPTION_THROWN then
ex := ORA_JAVA.LAST_EXCEPTION;
message(Exception_.toString(ex));
END;

This calls out to the Java class with two parameters. The Java class returns the exchange rate
that the code then displays as a message.
8. Run the form and click the button. The message line now displays the exchange rate from US
to UK currency.

Sample code and more information


Back to List of Topics

The following links point to more sources of information related to this topic.

Oracle Forms Services


Demo of calling a Web service from Forms (demo is near bottom of page)
Learn more about Web services at the Web Services Center on OTN
Using a WSDL to create a stub
Learn more about the Forms Java Importer

Place the cursor on this icon to hide all screenshots

Copyright © 2004 Oracle Corporation. All Rights Reserved.

You might also like