As explained in the introduction of this chapter, SOAP stands for Simple Object Access Protocol. It is a standard that defines how the message that calls the webservice should be defined and how the answer is returned. Both messages are in XML.
SOAP webservices can be defined in so-called Web Service Description Language (WSDL for short) documents. By reading a WSDL, an application knows what webservices are available, how to call them, and what response it can expect back. APEX uses the information in a WSDL document to generate the SOAP messages, without the developer having to do any programming.
In this recipe, we are going to show how we can call a SOAP webservice, using built-in functionality of Application Express.
Have an application ready. It doesn't have to be empty, as long as we can add new pages.
Also make sure that if you are working on an Oracle 11g database, that the host of each webservice that we are going to use is entered into the Access Control List (ACL) for the APEX user.
The ACL is a structure to allow access to network services. In earlier versions of the database, access was essentially granted to all services or none. In 11g this has been changed, so it is now possible to allow fine grained access to selected network services.
To allow the APEX_040000
user access to a network service like a webservice, we can use the following script:
begin dbms_network_acl_admin.create_acl (acl => 'acl_user.xml' ,description => 'Description' ,principal => 'APEX_040000' ,is_grant => true ,privilege => 'connect' ,start_date => null ,end_date => null); -- dbms_network_acl_admin.add_privilege (acl => 'acl_user.xml' ,principal => 'APEX_040000' ,is_grant => true ,privilege => 'resolve'), -- dbms_network_acl_admin.assign_acl (acl => 'acl_user.xml' ,host => 'name of website or host, i.e. soap.amazon.com'), -- commit; end;
[1346_08_01.txt]
This piece of code will do three things.
So these three together will allow the APEX_040000
user to resolve a network address and connect to it.
The ACL entries can be inspected by querying the database using the following query as a DBA user:
select * from dba_network_acls;
Their associated privileges can be found by using the following query, again as a DBA user:
select * from dba_network_acl_privileges;
Instead of a single URL for the host, a wildcard ('*') can be entered. But be careful when doing this, because this will allow any APEX user to connect to any network and internet address from any APEX application or PL/SQL code.
In this recipe, we are going to create a page and a report based on a webservice using the information from a WSDL document.
We are now in the wizard that will guide us through the creation process. On the first screen choose Based on WSDL and click Next.
We can see that APEX has gathered some information about the webservice by calling the WSDL document. It has found the name of the webservice, its endpoint and more importantly, the available operations to use. Later in the recipe, we will use the GetCityWeatherByZIP operation.
After creating the webservice reference, APEX gives us the option to inspect it or continue directly to build a page using the reference.
The next screen will allow us to create items that can be used in the webservice call. These have been generated based on the information from the WSDL. If the page number has changed, then rename the items accordingly. In this case, there is only one parameter, the input parameter to hold the zipcode for our webservice request.
You will see that APEX has created a straightforward page for us that will allow us to enter the required input parameter for the webservice. It has also created text fields for all the output parameters.
Try the webservice by entering an American zip code into the appropriate field (for the non-Americans; everybody remembers 90210 don't we?) and pressing Submit. This will result in the webservice returning an XML file with weather information for the chosen city. APEX automatically translates this data and enters it into the right fields on the screen.
3.147.84.157