oracle調用C#開發web servicesphp
1, 去oracle官網上下載dbws-callout-utility-10131.ziphtml
地址:https://oracle-base.com/articles/10g/utl_dbws-10g(注意請根據本身oracle的版原本選擇下載對應的jar)java
2, 解壓後放到oracle安裝目錄下的<oracle_install_dir>/sqlj/lib中;web
3, 在命令行中利用loadjava命令(通常安裝完jdk或oracle以後就會有)將jar包導入oracle對應的用戶中:sql
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.jaroracle
(本人每次都會使用SYS用戶權限比較大,在Win7與Win2008以後的系統開始命令行窗口的使用盡可能使用「管理員模式」,安裝時會產生拒絕訪問的狀況,有一種可能就是安裝的Oracle數據庫具有功能或者能夠把Oracle服務關了再試試(這句有機會真的能夠試試))socket
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>