oracle函数调用webservices 步骤:
1, 去oracle官网上下载dbws-callout-utility-10131.zip 下载地址:(1) http://www.oracle-base.com/articles/10g/utl_dbws-10g.php
(2) http://hi.baidu.com/love_lidx/item/ce779042995612a261d7b99f
2, 解压后将dbwsclientws.jar和dbwsclientdb11.jar(11代表oracle版本)放到oracle安装目录下的D:\app\Administrator\product\11.2.0\dbhome_1\sqlj\lib\中;
3, 导入java或jar 参数说明:
在cmd命令行中利用loadjava命令(一般安装完jdk或oracle之后就会有,jar包必须为绝对地址)将jar包导入oracle的sys用户中:
命令为:
loadjava -u sys/sys -o -r -v -f -genmissing -s -grant public D:\app\Administrator\product\11.2.0\dbhome_1\sqlj\lib\dbwsclientws.jar
loadjava -u sys/sys -o -r -v -f -genmissing -s -grant public D:\app\Administrator\product\11.2.0\dbhome_1\sqlj\lib\dbwsclientdb11.jar;
-o 使用OCI8 JDBC接口
-v 显示执行过程
-f 强制装载
-r 编译并解析类
4, 如果未发现UTL_DBWS(可以在plsql中敲入sys.若未有utl_dbws显示,则需要进行初始化),需要运行之前下载的包中dbws-callout-utility-10131/sqlj/lib/ utl_dbws_body.sql及utl_dbws_decl.sql(在sys用户下)
5.(执行以下sql)将权限付给需要用的数据库用户NSXYDJDBA:(需大写)
begin
dbms_java.grant_permission( 'NSXYDJDBA', 'SYS:java.lang.RuntimePermission', 'getClassLoader', '' );
dbms_java.grant_policy_permission('NSXYDJDBA','SYS','java.io.FilePermission','*');
---dbms_java.grant_permission( 'NSXYDJDBA','SYS:java.lang.IllegalAccessException','getClassLoader', '' );
dbms_java.grant_permission( 'NSXYDJDBA', 'SYS:java.lang.RuntimePermission', 'accessClassInPackage.sun.util.calendar', '' );
dbms_java.grant_permission( 'NSXYDJDBA', 'SYS:java.lang.RuntimePermission', 'setFactory', '' );
dbms_java.grant_permission( 'NSXYDJDBA', 'SYS:java.util.PropertyPermission', 'HTTPClient.socket.idleTimeout', 'write' );
dbms_java.grant_permission( 'NSXYDJDBA', 'SYS:java.net.SocketPermission', 'localhost', 'resolve' );
dbms_java.grant_permission( 'NSXYDJDBA', 'SYS:java.net.SocketPermission', '192.168.19.106:7001', 'connect,resolve' ); -----------接口地址
dbms_java.grant_permission( 'NSXYDJDBA', 'SYS:java.lang.RuntimePermission', 'createClassLoader', '' );
end;
6, 登录数据库NSXYDJDBA, 编写sql函数并发布
CREATE OR REPLACE FUNCTION add_func (str1 IN VARCHAR2,
str2 IN VARCHAR2)
RETURN VARCHAR2
AS
xml varchar2(9000);
l_service sys.UTL_DBWS.service;
l_call sys.UTL_DBWS.call;
l_wsdl_url VARCHAR2(32767);
l_namespace VARCHAR2(32767);
l_service_qname sys.UTL_DBWS.qname;
l_port_qname sys.UTL_DBWS.qname;
l_operation_qname sys.UTL_DBWS.qname;
l_xmltype_in SYS.XMLTYPE;
l_xmltype_out SYS.XMLTYPE;
l_return VARCHAR2(32767);
---l_input_params sys.UTL_DBWS.anydata_list;
BEGIN
xml:=replace(str1,'<','<');
xml:=replace(xml,'>','>');
l_wsdl_url := 'http://192.168.19.106:7001/wscxWeb_service/services/wscxWeb_service?wsdl';
l_namespace := 'http://service.hhzs.com';
l_service_qname := sys.UTL_DBWS.to_qname(l_namespace, 'wscxWeb_service');
l_port_qname := sys.UTL_DBWS.to_qname(l_namespace, 'wscxWeb_serviceHttpPort');
l_operation_qname := sys.UTL_DBWS.to_qname(l_namespace, 'IwscxService_client');
l_service := sys.UTL_DBWS.create_service (
wsdl_document_location => URIFACTORY.getURI(l_wsdl_url),
service_name => l_service_qname);
l_call := sys.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"?>
<IwscxService_client xmlns="' || l_namespace || '">
<str1>' || xml || '</str1>
<str2>' || str2 || '</str2>
</IwscxService_client>');
l_xmltype_out := sys.UTL_DBWS.invoke(call_Handle => l_call,
request => l_xmltype_in);
sys.UTL_DBWS.release_call (call_handle => l_call);
sys.UTL_DBWS.release_service (service_handle => l_service);
l_return := l_xmltype_out.extract('/').getStringVal();
--l_return := '1';
RETURN l_return;
END;
7,测试:select add_func ('<?xml version="1.0" encoding="UTF-8"?><REQUESTCODES ID="WSSSCX.GT3.SWDJX
XCX" NAME="税务登记信息查询请求报文" LX="0" ><CODE><NSRSBH>371325751788249
</NSRSBH><NSRMC></NSRMC><PAGE>1</PAGE><PAGESIZE>10</PAGESIZE></CODE></REQUESTCODES>','192.168.0.101') from dual;
测试成功!
8.注:如果不小心将jar加载到了oracle的其他的用户下,可用dropjava 命令卸载已经加载的jar包。用法和loadjava的用户相同。
本文原创,转载必追究版权。