Oracle 12,不建议使用的utl_dbws

i1icjdpr  于 2022-11-03  发布在  Oracle
关注(0)|答案(2)|浏览(168)

在oracle 12 c包中,utl_dbws(utl_dbws.invoke()--调用服务)被弃用(旧的,不惜一切代价避免使用:))。
我应该在oracle/plsql 12 c中使用什么?我试着问谷歌一些类似“utl_dbws等效12 c”等的东西,但没有具体的。
有什么建议吗?

e4yzc0pl

e4yzc0pl1#

使用UTL_HTTP包,这里有一个例子。如果你在谷歌上搜索“用UTL_HTTP调用Web服务”,那么你应该会找到几个教程。

FUNCTION GenerateRequest RETURN XMLTYPE IS
    res XMLTYPE;
BEGIN

    SELECT  
        XMLELEMENT("soapenv:Envelope", 
            XMLATTRIBUTES(
                'http://schemas.xmlsoap.org/soap/envelope/' AS "xmlns:soapenv", 
                'http://service.xxxxx.xxxxxx.com/' AS "xmlns:ser"),
            XMLELEMENT("soapenv:Header"),
            XMLELEMENT("soapenv:Body", 
                XMLELEMENT("ser:getAffectedServices",
                    XMLELEMENT("arg0",
                        XMLELEMENT("appName", 'com'),
                        XMLELEMENT("asmTicket", 'dummy'),
                        XMLELEMENT("instanceName", 'PAMOSS'),
                        XMLELEMENT("principal", 'dummy')
                    ),
                    XMLELEMENT("arg1", 1),
                    XMLELEMENT("arg2", 'some value'),                   
                    XMLELEMENT("arg3", 'basic')
                )
            )
        )
    INTO res
    FROM dual;

    RETURN res;

END GenerateRequest;

PROCEDURE getAffectedServices IS

   l_http_request    UTL_HTTP.REQ;
   l_http_response   UTL_HTTP.RESP;
   BUFFER VARCHAR2(32767);
   l_response_clob   CLOB;
    p_soap_msg CLOB;
    msg_length INTEGER;
    p_url VARCHAR2(4000) := 'http://service.xxxx.xxxx.com';

    amount INTEGER := 10000;
    OFFSET INTEGER := 1;

BEGIN

    p_soap_msg := GenerateRequest.GetClobVal();
    msg_length := DBMS_LOB.GETLENGTH(p_soap_msg);

    -- Prepare the header
    UTL_HTTP.SET_TRANSFER_TIMEOUT(300);
   l_http_request := UTL_HTTP.BEGIN_REQUEST(p_url, 'POST', UTL_HTTP.HTTP_VERSION_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', msg_length);

   -- Send message body
    LOOP
        EXIT WHEN OFFSET > msg_length;
        DBMS_LOB.READ(p_soap_msg, amount, OFFSET, BUFFER);
        UTL_HTTP.WRITE_TEXT(l_http_request, BUFFER);
        OFFSET := OFFSET + amount;
    END LOOP;
   -- Retrieve the response from web service
   l_http_response := UTL_HTTP.GET_RESPONSE(l_http_request);

   DBMS_LOB.CREATETEMPORARY(l_response_clob, TRUE, DBMS_LOB.CALL);
   DBMS_LOB.OPEN(l_response_clob, DBMS_LOB.LOB_READWRITE);

    -- Read the response message     
    BEGIN
    LOOP
        UTL_HTTP.READ_TEXT(l_http_response, BUFFER, 8192);
        DBMS_LOB.WRITEAPPEND(l_response_clob, LENGTH(BUFFER), BUFFER);
    END LOOP;
    EXCEPTION
        WHEN UTL_HTTP.END_OF_BODY THEN
            UTL_HTTP.END_RESPONSE(l_http_response);
    END;
   DBMS_LOB.CLOSE(l_response_clob);

   -- > Do whatever you like to do with XMLTYPE(l_response_clob);

   DBMS_LOB.FREETEMPORARY(l_response_clob);

END getAffectedServices;
ru9i0ody

ru9i0ody2#

我们能够使用数据库中的APEX调用Oracle19c中的Web服务:

-- Get the XML response from the web service.
    l_xmltype_out := APEX_WEB_SERVICE.make_request(
        p_url      => l_endpoint_url
      , p_action   => 'http://ORG.PROGRAM.Services.gov/ICalculator/AddNumbers'
      , p_envelope => l_envelope
    );

l_envelope是soap请求(从soapui获得)。l_xmlstype_out是返回的内容(它与soap ui的响应值匹配)。我们将soap请求和响应主体记录在一个表中,并定期清除它们以进行故障排除。

相关问题