UTL_DBWS - Consuming Web Services in Oracle 10g Onward

from:http://oracle-base.com/articles/10g/utl_dbws-10g.php

In a previous article I presented a method for Consuming Web Services using a basic SOAP implementation. This article provides similar functionality, but this time using the UTL_DBWS package, which is essentially a PL/SQL wrapper over JPublisher.

First, download the latest copy of the dbwsclient.jar file:

Extract the jar file from the zip file into the "$ORACLE_HOME/sqlj/lib" directory.

The jar file can be loaded into the SYS schema for everyone to access, or into an individual schema that needs access to the web client. To make sure you avoid errors during the load, set the JAVA_POOL_SIZE initialization parameter to at least 150M.

export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1

# Load into the SYS schema.
export PATH=$ORACLE_HOME/bin:$PATH
cd $ORACLE_HOME/sqlj/lib
# 10gR2
loadjava -u sys/password -r -v -f -genmissing -s -grant public dbwsclientws.jar dbwsclientdb102.jar
# 11g and 12c
loadjava -u sys/password -r -v -f -genmissing -s -grant public dbwsclientws.jar dbwsclientdb11.jar

# Load into an individual schema.
export PATH=$ORACLE_HOME/bin:$PATH
cd $ORACLE_HOME/sqlj/lib
# 10gR2
loadjava -u scott/tiger -r -v -f -genmissing dbwsclientws.jar dbwsclientdb102.jar
# 11g & 12c
loadjava -u scott/tiger -r -v -f -genmissing dbwsclientws.jar dbwsclientdb11.jar

In Oracle 10g the UTL_DBWS package is loaded by default. In Oracle 9i, 11g and 12c the package must be loaded using the specification and body provided in the zip file. The execute privilege should be granted on the ULT_DBWS package to any users needing access to the functionality.

$ cd $ORACLE_HOME/sqlj/lib
$ sqlplus / as sysdba

SQL> @utl_dbws_decl
SQL> @utl_dbws_body

SQL> CREATE PUBLIC SYNONYM utl_dbws FOR sys.utl_dbws;
SQL> GRANT EXECUTE ON sys.utl_dbws TO test;

The function below uses the UTL_DBWS package to access a web services from PL/SQL. The URL of the WDSL file describing the web service is shown here (http://oracle-base.com/webservices/server.php?wsdl). The web service accepts two number parameters and returns the sum of those values.

CREATE OR REPLACE FUNCTION add_numbers (p_int_1 IN NUMBER,
                                        p_int_2 IN NUMBER)
  RETURN NUMBER
AS
  l_service          UTL_DBWS.service;
  l_call             UTL_DBWS.call;

  l_wsdl_url         VARCHAR2(32767);
  l_namespace        VARCHAR2(32767);
  l_service_qname    UTL_DBWS.qname;
  l_port_qname       UTL_DBWS.qname;
  l_operation_qname  UTL_DBWS.qname;

  l_xmltype_in       SYS.XMLTYPE;
  l_xmltype_out      SYS.XMLTYPE;
  l_return           NUMBER;
BEGIN
  l_wsdl_url        := ‘http://oracle-base.com/webservices/server.php?wsdl‘;
  l_namespace       := ‘http://oracle-base.com/webservices/‘;

  l_service_qname   := UTL_DBWS.to_qname(l_namespace, ‘Calculator‘);
  l_port_qname      := UTL_DBWS.to_qname(l_namespace, ‘CalculatorPort‘);
  l_operation_qname := UTL_DBWS.to_qname(l_namespace, ‘ws_add‘);

  l_service := UTL_DBWS.create_service (
    wsdl_document_location => URIFACTORY.getURI(l_wsdl_url),
    service_name           => l_service_qname);

  l_call := UTL_DBWS.create_call (
    service_handle => l_service,
    port_name      => l_port_qname,
    operation_name => l_operation_qname);

  l_xmltype_in := SYS.XMLTYPE(‘<?xml version="1.0" encoding="utf-8"?>
    <ws_add xmlns="‘ || l_namespace || ‘">
      <int1>‘ || p_int_1 || ‘</int1>
      <int2>‘ || p_int_2 || ‘</int2>
    </ws_add>‘);
  l_xmltype_out := UTL_DBWS.invoke(call_Handle => l_call,
                                   request     => l_xmltype_in);

  UTL_DBWS.release_call (call_handle => l_call);
  UTL_DBWS.release_service (service_handle => l_service);

  l_return := l_xmltype_out.extract(‘//return/text()‘).getNumberVal();
  RETURN l_return;
END;
/

The output below shows the function in action.

SELECT add_numbers(1, 5) FROM dual;

ADD_NUMBERS(1,5)
----------------
               6

SQL>

SELECT add_numbers(10, 15) FROM dual;

ADD_NUMBERS(10,15)
------------------
                25

SQL>

For more information see:

时间: 2024-10-12 23:53:55

UTL_DBWS - Consuming Web Services in Oracle 10g Onward的相关文章

BizTalk调用WS-Security的web services

最近做个项目,biztalk跟OTM(Oracle Transportation Management)系统做对接,双方通过web services通讯,这部分是BizTalk调用OTM的web services. OTM的云服务,仅支持WS-Security的Username Token验证方式. 所以需要使用UsernameToken Web Service Security Policy,并使用HTTPS加密此SOAP消息的传输. OTM发布的web services是基于java的,也就

Redhat 5.4 + ASM + RAW+ Oracle 10g RAC 安装文档

基于Redhat 5 和redhat 4 的RAC 区别在对raw的处理上. 之前做的是redhat 4.7 的 RAC 实验. 准备做一个Redhat 5.4 的环境. RAC 的一些理论东西: http://blog.csdn.net/tianlesoftware/archive/2010/02/27/5331067.aspx RAW+ASM+ REDHAT 4.7 RAC 文档 http://blog.csdn.net/tianlesoftware/archive/2010/02/27/5

Zero Downtime Upgrade of Oracle 10g to Oracle 11g Using GoldenGate — 1

Source Database DB Name:        zwc Schemas:         HR,OE,PM Version:          10.2.0.4 RAC:                No OS Version:     Red Hat Enterprise Linux Server release 5.9 x86_64 OGG Version:   Oracle GoldenGate V11.2.1.0.6 for Oracle 10g on Linux x8

Oracle简易界面工具 (Oracle 10g, Oracle 11g)

Oracle简易界面工具 背景:偶在远程机上干活,须要调用到 Oracle 11gserver的数据,远程机上已安装Oracle client, 但 sql plus 和 sql developer 及 pl sql developer 都不能用 (DBA折腾几天都没解决).偶 有server的ip, oracleusername及password:知道部分表名及字段名. 因时间紧,偶仅仅好自己写一个简易的界面工具来应急. 演示效果:     演示下载: http://pan.baidu.com

安装Oracle 10g和SQLServer2008(仅作学习使用VirtualBox虚拟机来安装节省电脑资源)

1.虚拟机和宿主机共享文件夹. 2.右ctrl+F切换VirtualBox全屏 3.安装Oracle 10g 4.输入密码:root------------>下一步 5.勾选网络配置"用户已验证" 6.出现概要预览--------->直接点击"安装" 7.等待...出现如下界面后点击"口令管理" 8.解锁两个账户,并创建密码.scott/tiger  sys/root HR/hr----------->确定----------&

使用Apache Axis2 创建 Web Services (bottom-up)

使用Apache Axis2 创建 Web Services 一.什么是Web Services 简单来说Web Services 就是一种资源,我们可以通过http访问它,它以xml形式返回我们想要的结果. 二.Web 应用程序和web services对比 Web 应用程序 Web Services 返回HTML 返回XML(SOAP) 通过GET或POST形式提交数据 通过XML(SOAP)提交数据 结果返回给浏览器 结果返回给应用程序 三.Web Services组件 SOAP(Simp

CENTOS 6.4 安装oracle 10g,手工建库及升级到10.2.0.5

一. 数据库软件安装 参照官方手册 1.安装rpm包 注这里的yum直接用163的yum yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc.i686 glibc-common glibc-devel glibc-devel.i686 glibc-headers ksh libaio li

oracle 10g运维手册

1.    检查数据库基本状况... 4 1.1.     检查Oracle实例状态... 4 1.2.     检查Oracle服务进程... 4 1.3.     检查Oracle监听状态... 5 2.    检查系统和oracle日志文件... 6 2.1.     检查操作系统日志文件... 6 2.2.     检查oracle日志文件... 6 2.3.     检查Oracle核心转储目录... 7 2.4.     检查Root用户和Oracle用户的email. 7 3.  

oracle 10g rac 修改public ip、vip和private ip

oracle 10g rac 修改public ip.vip和private ip [TOC] 1.IP地址规划 Hostname 当前IP 修改后IP Public IP node1 192.168.56.20 192.168.100.20 Public IP node2 192.168.56.21 192.168.100.21 VIP node1-vip 192.168.56.98 192.168.100.98 VIP node2-vip 192.168.56.99 192.168.100.