oracle直接调用web services
oracle调用C#开发web services
1, 去oracle官网上下载dbws-callout-utility-10131.zip
地址:https://oracle-base.com/articles/10g/utl_dbws-10g(注意请根据自己oracle的版本来选择下载对应的jar)
2, 解压后放到oracle安装目录下的<oracle_install_dir>/sqlj/lib中;
3, 在命令行中利用loadjava命令(一般安装完jdk或oracle之后就会有)将jar包导入oracle对应的用户中:
loadjava -u user/password@oracle -r -v -f -genmissing -s -grant public dbwsclientws.jar dbwsclientdb102.jar
若为SYS用户,命令为:
loadjava -u user/password -r -v -f -genmissing -s -grant public dbwsclientws.jar dbwsclientdb102.jar
(本人每次都会使用SYS用户权限比较大,在Win7与Win2008之后的系统开始命令行窗口的使用尽量使用“管理员模式”,安装时会产生拒绝访问的情况,有一种可能就是安装的Oracle数据库具备功能或者可以把Oracle服务关了再试试(这句有机会真的可以试试))
4, 如果未发现UTL_DBWS(可以在plsql中敲入sys.若未有utl_dbws显示,则需要进行初始化),需要运行之前下载的包中dbws-callout-utility-10131/sqlj/lib/ utl_dbws_body.sql及utl_dbws_decl.sql
5, 编写sql函数并发布
create or replace function FUNC_GENERATE_LOGINNAME(content VARCHAR2,cellNumber VARCHAR2,sender VARCHAR2)
return VARCHAR2 AS
l_service sys.utl_dbws.SERVICE;
l_call sys.utl_dbws.call;
l_result ANYDATA;
l_wsdl_url VARCHAR2(1024);
l_service_name VARCHAR2(200);
l_operation_name VARCHAR2(200);
l_input_params sys.UTL_DBWS.anydata_list;
l_xmltype_in SYS.XMLTYPE;
l_xmltype_out SYS.XMLTYPE;
BEGIN
l_wsdl_url := 'http://xxxx.xxxx.xxxx.xxxx:xxxx/project/axis/services.jws?wsdl';(这里一定要加?wsdl)
l_service_name := 'servicesService';(就是我们*.asmx的那个类名)
l_operation_name := 'sendMessage';(就是我们具有WebMothed属性的方法名)
l_service := sys.UTL_DBWS.create_service(wsdl_document_location => URIFACTORY.getURI(l_wsdl_url),
service_name => l_service_name);
l_call := sys.UTL_DBWS.create_call(service_handle => l_service,
port_name => NULL,
operation_name => l_operation_name);
l_input_params(1) := ANYDATA.ConvertVarchar2(content);
l_input_params(2) := ANYDATA.ConvertVarchar2(cellNumber);
l_input_params(3) := ANYDATA.ConvertVarchar2(sender);
l_result := sys.UTL_DBWS.invoke(call_handle => l_call,
input_params => l_input_params);
sys.UTL_DBWS.release_call(call_handle => l_call);
sys.UTL_DBWS.release_service(service_handle => l_service);
RETURN ANYDATA.AccessVarchar2(l_result);
EXCEPTION
WHEN OTHERS THEN
RETURN substr(sqlerrm, 0, 2000);
END FUNC_GENERATE_LOGINNAME;
6,看结果select func_generate_loginname('testTest','1234567','xxxxxx') from dual;
7对于其中出现的异常,最可能的就是出现权限不足,可以利用如下语句解决:
begin
dbms_java.grant_permission( 'DZZWPT', 'SYS:java.lang.RuntimePermission', 'getClassLoader', '' );
dbms_java.grant_policy_permission('DZZWPT','SYS','java.io.FileP ermission','*');
---dbms_java.grant_permission( 'DZZWPT','SYS:java.lang.IllegalAccessException','getClassLoader', '' );
dbms_java.grant_permission( 'DZZWPT', 'SYS:java.lang.RuntimePermission', 'accessClassInPackage.sun.util.calendar', '' );
dbms_java.grant_permission( 'DZZWPT', 'SYS:java.lang.RuntimePermission', 'setFactory', '' );
dbms_java.grant_permission( 'DZZWPT', 'SYS:java.util.PropertyPermission', 'HTTPClient.socket.idleTimeout', 'write' );
dbms_java.grant_permission( 'DZZWPT', 'SYS:java.Net.SocketPermission', 'localhost', 'resolve' );
dbms_java.grant_permission( 'DZZWPT', 'SYS:java.net.SocketPermission', '192.168.21.203:80', 'connect,resolve' );
dbms_java.grant_permission( 'DZZWPT', 'SYS:java.lang.RuntimePermission', 'createClassLoader', '' );
end;
8.以上为官方实例,接下来我们来试试HelloWorld1).首先,我们要对自己写的WebServer做一些修改,
在WebServer类前面把Namespace设为空,且把[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
根据WebServer中的说明来确定输入参数、输出参数的格式
l_xmltype_in 的值就是<HelloWorld />
输出就是
<HelloWorld1Response>
<HelloWorld1Result>Hello World</HelloWorld1Result>
</HelloWorld1Response>