ORACLE WEBService调用

create or replace function soap_call
  ( p_req_body       in varchar2
  , p_target_url in varchar2
  , p_soap_action in varchar2 default 'none'
  ) return xmltype
  is
    l_soap_request  varchar2(30000);
    l_soap_response varchar2(30000);
    http_req utl_http.req;
    http_resp utl_http.resp;
  begin
    l_soap_request := '
    '|| p_req_body ||'';
    http_req:= utl_http.begin_request
               ( p_target_url
               , 'POST'
               , 'HTTP/1.1'
               );
    utl_http.set_header(http_req, 'Content-Type', 'text/xml; charset=UTF8');
    utl_http.set_header(http_req, 'Content-Length', length(l_soap_request));
    utl_http.set_header(http_req, 'SOAPAction', p_soap_action);
    utl_http.write_text(http_req, l_soap_request);
    -- the actual call to the service is made here
    http_resp:= utl_http.get_response(http_req);
    utl_http.read_text(http_resp, l_soap_response);
    utl_http.end_response(http_resp);

    -- only return from the soap response - that is: the content of the body element in the SOAP envelope
    return XMLType.createXML(l_soap_response).extract('/S:Envelope/S:Body/child::node()'
                     , 'xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"');
  end;

--webservice调用代码
CREATE OR REPLACE FUNCTION SEND_INDUCED_MESSAGE
(
    p_SIMNUM              IN VARCHAR2
  , p_HEIGHT              IN VARCHAR2 DEFAULT '32'
  , p_WIDTH               IN VARCHAR2 DEFAULT '0'
  , p_COLOR               IN VARCHAR2 DEFAULT '1'
  , p_PARKNUM             IN VARCHAR2
) RETURN VARCHAR2 AS
  l_response_call          XMLType;
  l_request_body           varchar2(20000);
  l_target_namespace       varchar2(200);
  l_target_url             varchar2(200);
BEGIN
  l_target_namespace  := 'http://led.innotek.com/';
  l_target_url        := 'http://192.168.10.100:8080/WebApplication/LedDisplayServiceService';
  l_request_body      :=
       '
            '||p_SIMNUM||'
            '||p_HEIGHT||'
            '||p_WIDTH||'
            '||p_COLOR||'
            '||p_PARKNUM||'
        ';
  l_response_call := soap_call(l_request_body, l_target_url, 'sendtext');
  return l_response_call.extract('//return/text()').getStringVal();
END ;

--创建控制列表并赋权 begin dbms_network_acl_admin.create_acl( acl => 'utl_http.xml', description => 'Http Access', principal => 'SMARTFEE', is_grant => TRUE, privilege => 'connect', start_date => null, end_date => null ); --添加新用户
dbms_network_acl_admin.add_privilege ( acl => 'utl_http.xml', principal => 'SMARTFEE', is_grant => TRUE, privilege => 'resolve', start_date => null, end_date => null ); --给网络分配一个访问控制列表
dbms_network_acl_admin.assign_acl ( acl => 'utl_http.xml', host => 'sms.pf.innotek.com', lower_port => 8880, upper_port => 8880 ); commit; end; /

--访问控制列表视图


select * from DBA_NETWORK_ACLS;


select * from DBA_NETWORK_ACL_PRIVILEGES;


select * from USER_NETWORK_ACL_PRIVILEGES;



SELECT *
FROM TABLE(DBMS_NETWORK_ACL_UTILITY.domains('www.chinastock.com.cn'));






--测试


DECLARE
l_url VARCHAR2(300) := 'http://www.test.com.cn/stock.xml';


l_http_request UTL_HTTP.req;


l_http_response UTL_HTTP.resp;


BEGIN
-- Make a HTTP request and get the response.


l_http_request := UTL_HTTP.begin_request(l_url);


l_http_response := UTL_HTTP.get_response(l_http_request);


UTL_HTTP.end_response(l_http_response);

END;

 

你可能感兴趣的:(oracle)