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:


转载于:https://www.cnblogs.com/wanghang/p/6299016.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值