Invoking Webservice from PL/SQL (UTL_DBWS&UTL_HTTP)

90 篇文章 1 订阅
34 篇文章 0 订阅
从PL/SQL,Oracle提供了两种方式调用外部Webservice:一种是UTL_HTTP,另外一种是UTL_DBWS。
  • utl_http – low level http assembler
  • utl_dbws – high level web service package

UTL_HTTP

•Available as of 8.0.5
•Send/receive raw HTTP request/responses to external servers
•Advantages:
Simplistic
–Installed (completely) in the database
–Passed and returns a VARCHAR2 XML payload
–Very easy if you know the XML payload structures
–Doesn't require a WSDL at publisher's site
–Good examples available on the internet
–3 rdparty PL/SQL wrappers available (Tim Hall:  soap_api)
•Disadvantages:
–Low level with no smarts to support web services
–Cryptic HTTP error messages
Oracle documentation is less than useful

UTL_DBWS

  • Available as of 10gR1
  • PL/SQL Java wrapper on oracle.jpub.runtime.dbws.DbwsProxy
  • Part of JPublisher
  • Advantages:
                    - High(er) level web service handler

  • Disadvantages:
-Not completely installed by default (bah!)
-Poor error reporting (in particular HTTP)
-Queries external WSDL each request
-Oracle documentation is dismal
-Use of HttpUriType does not support wallets or proxies
-Minor bugs in 10gR2 version with external authentication
-Minor issues on calling .Net web services
-Uses database JVM

UTL_HTTP现在已经逐步取代UTL_DBWS。

UTL_HTTP Sample


DECLARE
  L_PARAM_LIST VARCHAR2(512);

  L_HTTP_REQUEST  UTL_HTTP.REQ;
  L_HTTP_RESPONSE UTL_HTTP.RESP;

  L_RESPONSE_TEXT VARCHAR2(32767);
BEGIN

  -- service's input parameters
  L_PARAM_LIST := 'FromCurrency=EUR&ToCurrency=USD';

  -- preparing Request...
  L_HTTP_REQUEST := UTL_HTTP.BEGIN_REQUEST('http://www.webservicex.net/currencyconvertor.asmx/ConversionRate',
                                           'POST',
                                           'HTTP/1.1');

  -- ...set header's attributes
  UTL_HTTP.SET_HEADER(L_HTTP_REQUEST,
                      'Content-Type',
                      'application/x-www-form-urlencoded');
  UTL_HTTP.SET_HEADER(L_HTTP_REQUEST,
                      'Content-Length',
                      LENGTH(L_PARAM_LIST));

  -- ...set input parameters
  UTL_HTTP.WRITE_TEXT(L_HTTP_REQUEST, L_PARAM_LIST);

  -- get Response and obtain received value
  L_HTTP_RESPONSE := UTL_HTTP.GET_RESPONSE(L_HTTP_REQUEST);

  UTL_HTTP.READ_TEXT(L_HTTP_RESPONSE, L_RESPONSE_TEXT);

  DBMS_OUTPUT.PUT_LINE(L_RESPONSE_TEXT);

  -- finalizing
  UTL_HTTP.END_RESPONSE(L_HTTP_RESPONSE);

EXCEPTION
  WHEN UTL_HTTP.END_OF_BODY THEN
    UTL_HTTP.END_RESPONSE(L_HTTP_RESPONSE);
END;

UTL_DBWS Sample

 DECLARE
   v_namespace        VARCHAR2(1000) := 'http://www.sagecomputing.com.au/emp';
   v_service_qname    utl_dbws.qname := utl_dbws.to_qname(v_namespace,'employees');
   v_port_qname       utl_dbws.qname := utl_dbws.to_qname(v_namespace,'employeesSoapHttpPort');
   v_operation_qname  utl_dbws.qname := utl_dbws.to_qname(v_namespace,'getName');

   v_service           utl_dbws.service;
   v_call              utl_dbws.call;

   v_int_type          utl_dbws.qname;
   v_string_type       utl_dbws.qname;

   v_request_params    utl_dbws.anydata_list; -- RPC style only
   v_response_anydata  AnyData;               -- RPC style only

   v_request_xmltype   XmlType;               -- Document style only
   v_response_xmltype  XmlType;               -- Document style only   

BEGIN
   v_service := utl_dbws.create_service(
     HttpUriType('http://www.sage.com.au/employees?wsdl'), v_service_qname);

   v_call := utl_dbws.create_call(v_service, v_port_qname, v_operation_qname);

   utl_dbws.set_property(v_call, 'SOAPACTION_USE',    'TRUE');
   utl_dbws.set_property(v_call, 'SOAPACTION_URI',    'getName');
   utl_dbws.set_property(v_call, 'ENCODINGSTYLE_URI',
    'http://schemas.xmlsoap.org/soap/encoding/');  
   utl_dbws.set_property(v_call, 'OPERATION_STYLE',   'rpc');

   utl_dbws.set_property(v_call, 'OPERATION_STYLE',   'document');
   utl_dbws.set_property(v_call, 'OPERATION_STYLE',   'rpc');

   v_int_type    := utl_dbws.to_qname('http://www.w3.org/2001/XMLSchema', 'int');
   v_string_type := utl_dbws.to_qname('http://www.w3.org/2001/XMLSchema', 'string');

   utl_dbws.add_parameter(v_call, 'employeeNumber', v_int_type,    'ParameterMode.IN');
   utl_dbws.add_parameter(v_call, 'nameCase',       v_string_type, 'ParameterMode.IN');
   utl_dbws.set_return_type(v_call, v_string_type);  

   v_request_params(0) := AnyData.convertNumber(1234);
   v_request_params(1) := AnyData.convertVarchar('M');

   v_response_anydata := utl_dbws.invoke(v_call, v_request_params);
   dbms_output.put_line('Result = ' || v_response_anydata.accessVarchar2);

   utl_dbws.release_call(v_call);
   utl_dbws.release_service(v_service);
END;
/
Result = Christopher Muir


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
[ 2%] Generating dynamic reconfigure files from cfg/Depth.cfg: /home/ubuntu/new_workspace/devel/include/depthimage_to_laserscan/DepthConfig.h /home/ubuntu/new_workspace/devel/lib/python2.7/dist-packages/depthimage_to_laserscan/cfg/DepthConfig.py Generating reconfiguration files for Depth in depthimage_to_laserscan Wrote header file in /home/ubuntu/new_workspace/devel/include/depthimage_to_laserscan/DepthConfig.h [ 2%] Built target depthimage_to_laserscan_gencfg Scanning dependencies of target lslidar_serial_x10 [ 2%] Building CXX object lsx10/lslidar_x10_driver/CMakeFiles/lslidar_serial_x10.dir/src/lsiosr.cpp.o [ 2%] Linking CXX shared library /home/ubuntu/new_workspace/devel/lib/liblslidar_serial_x10.so [ 2%] Built target lslidar_serial_x10 Scanning dependencies of target lslidar_input_x10 [ 2%] Building CXX object lsx10/lslidar_x10_driver/CMakeFiles/lslidar_input_x10.dir/src/input.cc.o In file included from /home/ubuntu/new_workspace/src/lsx10/lslidar_x10_driver/src/input.cc:18:0: /home/ubuntu/new_workspace/src/lsx10/lslidar_x10_driver/include/lslidar_x10_driver/input.h:32:10: fatal error: pcap.h: No such file or directory #include <pcap.h> ^~~~~~~~ compilation terminated. lsx10/lslidar_x10_driver/CMakeFiles/lslidar_input_x10.dir/build.make:62: recipe for target 'lsx10/lslidar_x10_driver/CMakeFiles/lslidar_input_x10.dir/src/input.cc.o' failed make[2]: *** [lsx10/lslidar_x10_driver/CMakeFiles/lslidar_input_x10.dir/src/input.cc.o] Error 1 CMakeFiles/Makefile2:10548: recipe for target 'lsx10/lslidar_x10_driver/CMakeFiles/lslidar_input_x10.dir/all' failed make[1]: *** [lsx10/lslidar_x10_driver/CMakeFiles/lslidar_input_x10.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... [ 2%] Linking CXX shared library /home/ubuntu/new_workspace/devel/lib/libDepthImageToLaserScan.so [ 2%] Built target DepthImageToLaserScan [ 2%] Linking CXX shared library /home/ubuntu/new_workspace/devel/lib/libsba.so [ 2%] Built target sba Makefile:140: recipe for target 'all' failed make: *** [all] Error 2 Invoking "make -j4 -l4" failed
最新发布
05-26

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值