Oracle通过存储过程 采用HTTP的方式调用webserivce
只要是通过 utl_http 这个包来进行实现
直接上代码(Oracle 10G)
例子1
create or replace procedure httpwebservice2 is
env VARCHAR2(32767);
http_req utl_http.req;
http_resp utl_http.resp;
return_value xmltype;
error_value xmltype;
error_code VARCHAR(256);
error_string VARCHAR2(32767);
result_string varchar2(32767);
BEGIN
env := '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://server.webservice.simis.si.neusoft.com">
<soapenv:Header/>
<soapenv:Body>
<ser:ReportTheLossOfSIcard soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<keyInfo xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">452223193711161025||B20684791|4|402|6231330300051198182|450200D156000005A5209A7FE074EFAB|3B6D0000008159532086A24502A5209A7F4</keyInfo>
</ser:ReportTheLossOfSIcard>
</soapenv:Body>
</soapenv:Envelope>
';
http_req := utl_http.begin_request('http://10.154.248.13:7011/eapdomain_lz_zx/services/WSInterfaceSiINF?wsdl',
'POST',
'HTTP/1.0');
utl_http.set_header(http_req, 'Content-Type', 'text/xml');
utl_http.set_header(http_req, 'Content-Length', length(env));
/* utl_http.set_header(http_req,
'SOAPAction',
'http://www.webserviceX.NET/GetWeather');*/
utl_http.set_header(http_req,
'SOAPAction',
'');
utl_http.write_text(http_req, env);
http_resp := utl_http.get_response(http_req);
utl_http.read_text(http_resp, env);
utl_http.end_response(http_resp);
return_value := xmltype.createxml(env)
.extract('/soap:Envelope/soap:Body/child::node()',
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"');
error_value := return_value.extract('/soap:Fault',
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"');
if (error_value is not null) THEN
error_string := error_value.extract('/soap:Fault/faultstring/child::text()','xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"')
.getstringval();
error_code := error_value.extract('/soap:Fault/faultcode/child::text()','xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"')
.getstringval();
raise_application_error(-20000,
'error in authentification: ' || error_string ||
' - ' || error_code);
end if;
result_string := return_value.getStringVal();
dbms_output.put_line(result_string);
/*
result_string := replace(result_string, '<', '<');
result_string := replace(result_string, '>', '>');
result_string := replace(result_string, '"', '"');*/
--return result_string;
end httpwebservice2;
/
例子2
DECLARE
L_PARAM_LIST VARCHAR2(32767);
L_HTTP_REQUEST UTL_HTTP.REQ;
L_HTTP_RESPONSE UTL_HTTP.RESP;
L_RESPONSE_TEXT VARCHAR2(32767);
BEGIN
--452501195312120215|张昌义|K10131759|1
-- service's input parameters
L_PARAM_LIST := '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://server.webservice.simis.si.neusoft.com">
<soapenv:Header/>
<soapenv:Body>
<ser:ReportTheLossOfSIcard soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<keyInfo xsi:type="xsd:string">452501195312120215|张昌义|K10131759|1</keyInfo>
</ser:ReportTheLossOfSIcard>
</soapenv:Body>
</soapenv:Envelope>';
-- preparing Request...
L_HTTP_REQUEST := UTL_HTTP.BEGIN_REQUEST('http://10.154.232.38:9001/eapdomain_lz/services/WSInterfaceSiINF?wsdl',
'POST',
'HTTP/1.1');
-- ...set header's attributes
UTL_HTTP.SET_HEADER(L_HTTP_REQUEST,
'Accept-Encoding',
'gzip,deflate');
-- ...set header's attributes
UTL_HTTP.SET_HEADER(L_HTTP_REQUEST,
'Connection',
'Keep-Alive');
UTL_HTTP.SET_HEADER(L_HTTP_REQUEST,
'User-Agent',
'Apache-HttpClient/4.1.1');
UTL_HTTP.SET_HEADER(L_HTTP_REQUEST,
'Content-Type',
'text/xml; charset=UTF-8');
UTL_HTTP.SET_HEADER(L_HTTP_REQUEST,
'Content-Length',
'544');-- LENGTH(L_PARAM_LIST));
UTL_HTTP. set_header(L_HTTP_REQUEST,
'SOAPAction',
'ReportTheLossOfSIcard');
-- ...set input parameters
UTL_HTTP.WRITE_TEXT(L_HTTP_REQUEST, L_PARAM_LIST);
-- get Response and obtain received value
L_HTTP_RESPONSE := UTL_HTTP.GET_RESPONSE(L_HTTP_REQUEST);
UTL_HTTP.READ_TEXT(L_HTTP_RESPONSE, L_RESPONSE_TEXT);
DBMS_OUTPUT.PUT_LINE(L_RESPONSE_TEXT);
-- finalizing
UTL_HTTP.END_RESPONSE(L_HTTP_RESPONSE);
EXCEPTION
WHEN UTL_HTTP.END_OF_BODY THEN
UTL_HTTP.END_RESPONSE(L_HTTP_RESPONSE);
END;
例子3
DECLARE
L_PARAM_LIST VARCHAR2(32767);
L_HTTP_REQUEST UTL_HTTP.REQ;
L_HTTP_RESPONSE UTL_HTTP.RESP;
L_RESPONSE_TEXT VARCHAR2(32767);
BEGIN
-- service's input parameters
L_PARAM_LIST := '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://server.webservice.simis.si.neusoft.com">
<soapenv:Header/>
<soapenv:Body>
<ser:siCheckPassWord soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<strUserAkc020 xsi:type="xsd:string">100000052900495688</strUserAkc020>
<strPwd xsi:type="xsd:string">000529</strPwd>
</ser:siCheckPassWord>
</soapenv:Body>
</soapenv:Envelope>';
-- preparing Request...
L_HTTP_REQUEST := UTL_HTTP.BEGIN_REQUEST('http://10.154.232.38:9001/eapdomain_lz/services/WSInterfaceSiINF?wsdl',
'POST',
'HTTP/1.1');
-- ...set header's attributes
UTL_HTTP.SET_HEADER(L_HTTP_REQUEST,
'Content-Type',
'text/xml; charset=utf-8');--'application/x-www-form-urlencoded');
UTL_HTTP.SET_HEADER(L_HTTP_REQUEST,
'Content-Length',
LENGTH(L_PARAM_LIST));
UTL_HTTP. set_header(L_HTTP_REQUEST,
'SOAPAction',
'siCheckPassWord');--siCheckPassWord
-- ...set input parameters
UTL_HTTP.WRITE_TEXT(L_HTTP_REQUEST, L_PARAM_LIST);
-- get Response and obtain received value
L_HTTP_RESPONSE := UTL_HTTP.GET_RESPONSE(L_HTTP_REQUEST);
UTL_HTTP.READ_TEXT(L_HTTP_RESPONSE, L_RESPONSE_TEXT);
DBMS_OUTPUT.PUT_LINE(L_RESPONSE_TEXT);
-- finalizing
UTL_HTTP.END_RESPONSE(L_HTTP_RESPONSE);
EXCEPTION
WHEN UTL_HTTP.END_OF_BODY THEN
UTL_HTTP.END_RESPONSE(L_HTTP_RESPONSE);
END;