Skip to content

Usage with PL/SQL

The Web Service Call using PL/SQL is nothing more than a simple HTTP POST Request sent to the server along with the XML. As PL/SQL does not supply any libraries to facilitate the Consumption of Web Services, the following function could be added to the code to facilitate this process.

FUNCTION CALL_WEB_SERVICE(p_request  IN OUT  CLOB) RETURN CLOB IS    

 l_req         UTL_HTTP.REQ;
 l_resp        UTL_HTTP.RESP;   
 l_amount BINARY_INTEGER := 8000; 
 l_offset INTEGER := 1; 
 l_buffer CLOB; -- VARCHAR2(32000);
 l_buffer_line VARCHAR2(32000);      
 l_answer VARCHAR2(200);

BEGIN

  BEGIN
          UTL_HTTP.SET_TRANSFER_TIMEOUT(200);
          UTL_HTTP.SET_WALLET('file:/ORA/dbs01/syscontrol/etc/WALLETS/rdbms');
          l_req := UTL_HTTP.BEGIN_REQUEST(INFOR_WS_URI, 'POST', UTL_HTTP.HTTP_VERSION_1_1);
          UTL_HTTP.SET_HEADER(l_req, 'Content-Type', 'text/xml');
          UTL_HTTP.SET_HEADER(l_req, 'Content-Length', LENGTH(p_request));

          LOOP 
              DBMS_LOB.READ(p_request, l_amount, l_offset, l_buffer ); 
              UTL_HTTP.WRITE_TEXT(l_req, l_buffer);
              l_offset := l_offset + l_amount;
              l_amount := 8000;
          END LOOP;

     EXCEPTION 
          WHEN NO_DATA_FOUND THEN 
              l_resp := UTL_HTTP.GET_RESPONSE(l_req);
  END;     

  BEGIN

    l_buffer      := NULL;
    l_buffer_line := NULL;

    LOOP
      UTL_HTTP.read_text(l_resp, l_buffer_line); 
      l_buffer := l_buffer || l_buffer_line;
    END LOOP;

  EXCEPTION
    WHEN UTL_HTTP.end_of_body THEN
      NULL;

  END;

  UTL_HTTP.END_RESPONSE(l_resp);
  RETURN(l_buffer); 

EXCEPTION
  WHEN OTHERS THEN
  NULL;

END CALL_WEB_SERVICE;

Note

The XML Document must be passed in the p_request variable. The Function returns the Response returned by the Server.

Next Section

Comments from Sara

Show what happens when we use this functions maybe??


Last update: July 8, 2022