在開發過程中,涉及到多系統的部分數據交互,找了一些相關資料選定較爲成熟的webservice,web可以實現不同平臺、語言的交互,主要基於:HTTP+ XML(WSDL)方式。明細如下:
1、我們首先進行模擬一個服務端,進行端口發佈(Java):
@WebService
public class WsServer {
public static void main(String[] args) {
//在本機測試,此處IP地址也不要選擇localhost或者127.0.0.1
//後半段Service拼接類名 /Service/WsServer
Endpoint.publish("http://172.25.10.1:8086/Service/WsServer", new WsServer());
System.out.println("publish success...");
}
public String getHello(String a,String b,String c){
System.out.println("hello, " + a + b + c);
return "hello, " + a + b + c;
}
}
直接正常運行main函數,啓動線程開始進行監聽,執行結果如下:
此時爲了解我們的接口是否可以正常訪問,可以進行訪問測試,兩種方式如下:
方式一 瀏覽器輸入:http://172.25.10.1:8086/Service/WsServer?wsdl 注意拼接 ?wsdl,如下圖:
方式二 通過soapUI工具進行連接測試,出現如下結果爲接口正常(推薦)
oracle plsql存儲過程調用接口如下:
declare
arg0 VARCHAR2(200) ;
l_req_text VARCHAR2(32767);
l_req_raw RAW(32767);
l_req_blob BLOB;
l_buffer VARCHAR2(4000);
l_buffer_size INTEGER := 1000;
l_offset INTEGER := 1;
l_resp_raw RAW(32767);
l_resp_text VARCHAR2(32767);
http_req utl_http.req;
http_resp utl_http.resp;
x_flag VARCHAR2(10) := 'E';
x_err_msg VARCHAR2(2000);
begin
-- 給接口參數賦值
arg0 := '小明';
-- cast_to_raw 拼接內容爲標籤 可以直接複製 soapUI ,拼接傳入的參數即可
l_req_blob := to_blob(utl_raw.cast_to_raw('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:con="http://controller.toolslsy.lsy.com/">
<soapenv:Header/><soapenv:Body><con:getHello><arg0>1</arg0><arg1>2</arg1><arg2>3</arg2></con:getHello></soapenv:Body></soapenv:Envelope>'));
-- HTTP 配置如下 部分配置自行選擇
utl_http.set_transfer_timeout(300);
-- 配置接口地址 訪問方式
http_req := utl_http.begin_request('http://172.25.10.1:8086/Service/WsServer', 'POST', 'HTTP/1.0');
-- 內容字符集
utl_http.set_body_charset(http_req, 'UTF8');
utl_http.set_header(http_req, 'Content-Type', 'text/xml;charset=UTF-8');
utl_http.set_persistent_conn_support(http_req, TRUE);
utl_http.set_header(http_req,
'Content-Length',
dbms_lob.getlength(l_req_blob));
FOR i IN 1 .. ceil(dbms_lob.getlength(l_req_blob) / l_buffer_size) LOOP
l_buffer := dbms_lob.substr(l_req_blob, l_buffer_size, l_offset);
l_offset := l_offset + l_buffer_size;
utl_http.write_raw(http_req, l_buffer);
END LOOP;
http_resp := utl_http.get_response(http_req);
dbms_output.put_line('調用接口程序:' || http_resp.status_code || ' reason_phrase:' || http_resp.reason_phrase);
utl_http.read_raw(http_resp, l_resp_raw);
utl_http.end_response(http_resp);
-- 獲取接口訪問狀態
IF http_resp.status_code = '200' THEN
dbms_output.put_line('調用成功');
-- 獲取接口訪問內容
l_resp_text := convert(utl_raw.cast_to_varchar2(l_resp_raw),
'ZHS16GBK',
'UTF8');
--返回值輸出
dbms_output.put_line(l_resp_text);
ELSE
x_err_msg := '請求服務調用失敗(' || http_resp.status_code || '):' ||http_resp.reason_phrase;
END IF;
EXCEPTION
WHEN others THEN
x_err_msg := x_err_msg || '發送同步服務請求發生異常(' || SQLCODE || '):' || SQLERRM || '-';--utl_http.end_response(http_resp)
x_flag := 'E';
dbms_output.put_line(x_flag || '-' || x_err_msg );
END;
執行 declare 輸出結果:
java服務端輸出結果: