在开发过程中,涉及到多系统的部分数据交互,找了一些相关资料选定较为成熟的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服务端输出结果: