Oracle® Application Express Advanced Tutorials Release 3.2 Part Number E11945-01 |
|
|
View PDF |
Web services enable applications to interact with one another over the Web in a platform-neutral, language independent environment. In a typical Web services scenario, a business application sends a request to a service at a given URL by using the HTTP protocol. The service receives the request, processes it, and returns a response. You can incorporate calls to external Web services in applications developed in Oracle Application Express.
Web services in Oracle Application Express are based on SOAP (Simple Object Access Protocol). SOAP is a World Wide Web Consortium (W3C) standard protocol for sending and receiving requests and responses across the Internet. SOAP messages can be sent back and forth between a service provider and a service user in SOAP envelopes.
Web services are called from within an Oracle Application Express application by:
Using the Universal Description, Discovery, and Integration (UDDI) registry
Manually providing the WSDL URL
This tutorial illustrates the later method.
Topics in this section include:
Note:
The SOAP 1.1 specification is a W3C note. (The W3C XML Protocol Working Group has been formed to create a standard that will supersede SOAP.)For information about Simple Object Access Protocol (SOAP) 1.1 see:
http://www.w3.org/TR/SOAP/
See Also:
"Implementing Web Services" in Oracle Database Application Express User's GuideTo utilize Web services in Oracle Application Express, you create a Web service reference using a wizard. When you create the Web reference, you can follow one of these methods:
You supply the URL to a WSDL document. The wizard then analyzes the WSDL and collects all the necessary information to create a valid SOAP message.
The wizard provides a step where you can locate a WSDL using the Universal Description, Discovery, and Integration (UDDI) registry. A UDDI registry is a directory where businesses register their Web services. You search for the WSDL by entering either a service or business name.
You supply the relevant information on how to interact with the Web reference, including the SOAP request envelope, and create the Web reference manually.
This tutorial describes the second method, creating a Web service reference manually.
First, create a new application.
To create an application:
On the Workspace home page, click the Application Builder icon.
On the Application Builder home page, click Create.
For Method, select Create Application, and click Next.
For Name:
For Name - Enter Web Services
.
Accept the remaining defaults and click Next.
Add a blank page:
Under Select Page Type, accept the default, Blank.
In Page Name, enter Web Services
and then click Add Page.
The new page appears in the list at the top of the page.
Click Next.
For Tabs, accept the default, One Level of Tabs, and click Next.
For Shared Components, accept the default, No, and click Next.
For Attributes, accept the default for Authentication Scheme, Language, and User Language Preference Derived From and click Next.
For User Interface, select Theme 2 and click Next.
Review your selections and click Create.
The Application home page appears.
If your environment requires a proxy server to access the Internet, you must specify a proxy server address on the Application Attributes page before you can create a Web service reference.
To specify a proxy address:
On the Application home page, click Shared Components.
Under Application, click Definition.
Under Name, enter the proxy server in the Proxy Server field.
Click Apply Changes.
The Application home page appears.
In this exercise, you create a Web service by supplying the location of a WSDL document to a Web service. You then create a form and report for displaying movie theaters and locations.
Note:
The following exercise is dependent upon the availability of the specified Web service ultimately invoked. If the Web service is unavailable, you may experience difficulties completing this exercise.To create a new Web reference by supplying the WSDL location:
On the Application home page, click Shared Components.
The Shared Components page appears.
Under Logic, select Web Service References.
Click Create
When prompted whether to search a UDDI registry to find a WSDL, select No and click Next.
In the WSDL Location field enter:
http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx?wsdl
Click Next.
A summary page appears describing the selected Web service.
Click Create Reference.
The Create Web Service Reference page appears. The Web service reference for MovieInformation is added to the Web Service References Repository.
Next, you need to create a page that contains a form and report to use with your Web Service Reference.
To create a form and report after creating a Web Service Reference:
On the Create Web Service Reference success page, select Create Form and Report on Web Service.
For Choose Service and Operation:
Web Service Reference - Select MovieInformation.
Operation - Select GetTheatersAndMovies.
Click Next.
For Page and Region Attributes:
Form Region Title - Change to Theater Information
.
Accept the other defaults and click Next.
For Input Items:
For P2_ZIPCODE and P2_RADIUS, accept the default, Yes, in the Create column.
For P2_ZIPCODE, change the Item Label default to ZIP Code
.
Click Next.
For Web Service Results:
Temporary Result Set Name (Collection) - Accept the default.
Result Tree to Report On - Select Theater (tns:Theater).
Click Next.
For Result Parameters, select all the parameters and click Finish.
Click Run Page.
If prompted to log in, enter the user name and password for your workspace and click Login.
A form and report resembling Figure 7-1 appear. Notice that the Theater Information Form at the top of the page contains a data entry field and a submit button, but the Results Report does not contain any data.
Figure 7-1 Theater Information Form and Report without Data
To test the form, enter 43221
in the ZIP Code field and 5
in the Radius field. Then click Submit.
The report at the bottom of the page should resemble Figure 7-2. The report lists the names and addresses of movie theaters matching the entered ZIP code and radius.
Figure 7-2 Theater Information Report Showing Resulting Data
In this exercise, you create a Web reference by supplying information about the Web service and using the manual facility. Manual Web references are created by visually inspecting the WSDL document as well as using a tool to determine the SOAP envelope for the Web service request.
Topics in this section include:
To create a Web reference manually, you will copy code from the WSDL for a service called MovieInformation.
Please note the example settings provided in the following steps are based on the MovieInformation service at the time this document was released.
To create a manual Web reference:
On the Application home page, click Shared Components.
Under Logic, click Web Service References.
Click Create.
For Search UDDI, select No and click Next.
From the Tasks list on the right, click the Create Web Reference Manually link.
The Create/Edit Web Service page appears.
In the Name field, enter Movie Info
.
Locate the endpoint of the MovieInformation service:
Open the WSDL by going to:
http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx?wsdl
In the WSDL, find the location
attribute of the soap:address
element, which is a child of the port
element. You can search for the following term within the code: soap:address location.
At the time of this release, it was this attribute:
http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx
In the URL field on the Create/Edit Web Service page, enter the endpoint of the MovieInformation service you located. For example: http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx
Locate the SOAP action for the GetTheatersAndMovies
operation:
If necessary, open the WSDL again. See Step 7a.
In the WSDL, find the soapAction
attribute of the soap:operation
element, which is a child of the operation element that has a name attribute of GetTheatersAndMovies
. You can search for the following term within the code: soap:operation soapAction
.
At the time of this release, it was this attribute:
http://www.ignyte.com/whatsshowing/GetTheatersAndMovies
In the Action field on the Create/Edit Web Service page, enter the SOAP action you located. For example: http://www.ignyte.com/whatsshowing/GetTheatersAndMovies
In the SOAP Envelope field on the Create/Edit Web Reference page, enter the xml code representing the SOAP Request message. For example:
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://www.ignyte.com/whatsshowing" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <soap:Body> <tns:GetTheatersAndMovies> <tns:zipCode>#ZIP#</tns:zipCode> <tns:radius>#RADIUS#</tns:radius> </tns:GetTheatersAndMovies> </soap:Body> </soap:Envelope>
You can use a SOAP message generating tool, such as MindReef, to construct a valid SOAP Request for a given Web service.
In the Store Response in Collection field, enter MOVIE_RESULTS
. This is where the response from the Web service will be stored.
The Create/Edit Web Service page should resemble Figure 7-3.
Click Create.
The Web Service References page appears, showing Movie Info in the list.
To test the Web service:
On the Web Service References page, click the Test icon next to the Movie Info Web reference.
The Web Services Testing page appears.
Note View must be set to Details, otherwise the Test icon is not displayed.
In the SOAP Envelope field, replace #ZIP# with 43221
and #RADIUS# with 5
.
Click Test.
Review the Result field and note the following about the response:
The base node in the return envelope is called:
GetTheatersAndMoviesResponse
The namespace for the message is:
http://www.ignyte.com/whatsshowing
The XPath to the interesting parts of the response under the result element is:
/GetTheatersAndMoviesResponse/GetTheatersAndMoviesResult/Theater/Movies/Movie
The interesting elements in the results are called:
Name Rating RunningTime ShowTimes
Next, you want to create a page to call the manual Web Service.
To create a page to call the manual Web service:
Click the Application breadcrumb link.
On the Application home page, click Create Page.
For Page, select Blank Page and click Next.
Accept the default for the Page Number and click Next.
In Name, enter Find Movies
and click Next.
For Tabs, accept the default, No, and click Next.
Click Finish.
On the Success page, click Edit Page.
On the Page Definition, locate the Regions section.
Click the Create icon.
For Region, select HTML and click Next.
Select HTML as the HTML region container and click Next.
In the Title field, enter Movie Information
and click Next.
Click Create Region.
Next, you want to add a Submit button to the region to initiate a search from the page.
To create a Submit button:
On the Page Definition, click the Create icon in the Buttons section.
For Button Region, accept the default, Movie Information, and click Next.
For Button Position, accept the default, Create a button in a region position, and click Next.
For Button Attributes, enter SUBMIT
in the Button Name and click Next.
For Button Template, accept the default, Button, and click Next.
For Display Properties, select Region Template Position #CREATE# from the Position list and click Next.
In the Branch to Page field, select Find Movies from the list. The page number appears in the field.
Click Create Button.
Next, you want to create two items where users can enter a search term.
To create the ZIP Code item:
On the Find Movies Page Definition, click the Create icon in the Items section.
For Item Type, select Text and click Next.
For Text Control Display Type, accept the default, Text Field, and click Next.
For Display Position and Name, specify the following:
Item Name - Enter ZIP
.
The Movie Info Web Service Reference defines the zip code sent in the SOAP Request as #ZIP#. Therefore, this Item Name must be ZIP in order for it's value to be substituted into the SOAP Request sent to the Web Service.
Region - Accept the default, Movie Information.
Click Next.
In the Label field, replace the existing text with ZIP Code
and click Next.
Click Create Item.
To create the Radius item:
On the Find Movies Page Definition, click the Create icon in the Items section.
For Item Type, select Text and click Next.
For Text Control Display Type, accept the default, Text Field, and click Next.
For Display Position and Name, specify the following:
Item Name - Enter RADIUS
.
The Movie Info Web Service Reference defines the radius sent in the SOAP Request as #RADIUS#. Therefore, this Item Name must be RADIUS in order for it's value to be substituted into the SOAP Request sent to the Web Service.
Region - Accept the default, Movie Information.
Click Next.
In the Label field, enter Radius
and click Next.
Click Create Item.
Next, you want to create a process that calls the manually created Web reference.
To create a process to call the manually created Web reference:
On the Find Movies Page Definition, click the Create icon in the Processes section.
For Process Type, select Web Services and click Next.
In the Name field, enter Call Movie Info
and click Next.
From the Web Service Reference list, select Movie Info and click Next.
In the Success Message area, enter Called Movie Info
.
In the Failure Message area, enter Error calling Movie Info
and click Next.
From the When Button Pressed list, select SUBMIT and click Create Process.
Next, you want to add a report that displays the results of the called Web service.
To create a report on the Web service result:
On the Find Movies Page Definition, click the Create icon in the Regions section.
Select Report and click Next.
For Region, select Report on collection containing Web service result and click Next.
In the Title field, enter Search Results
and click Next.
For Web Reference Type, select Manually Created and click Next.
For Web Reference Information, specify the following:
Web Service Reference - Select Movie Info from the list.
SOAP Style - Select Document.
Message Format - Select Literal.
Note that these two attributes can be determined by manually inspecting the WSDL document for the service.
Result Node Path - Enter:
/GetTheatersAndMoviesResponse/GetTheatersAndMoviesResult/Theater/Movies/Movie
Message Namespace - Enter:
http://www.ignyte.com/whatsshowing
Note that you reviewed both the Result Node Path and Message Namespace when testing the service.
Click Next.
In the first four Parameter Names, enter Name
, Rating
, RunningTime
, and ShowTimes
, and click Create SQL Report.
To test the page:
Click Run Page. If prompted to log in, enter your workspace user name and password. The Movie Information form appears, as shown in Figure 7-4.
Figure 7-4 Movie Information Form with No Data
In the ZIP Code and Radius fields, enter information and click Submit.
The results appear in the Search Results area.