Sending SOAP Request through HTTP in PLSQL.


I was getting few queries about calling a webservice in PLSQL using HTTP protocol. We can use UTL_HTTP package to do it. Below is the example that calls SOAP service from PLSQL.

<code>

SET serveroutput on
DECLARE
   -- SOAP REQUESTS/RESPONSE
   soap_req_msg    VARCHAR2 (2000);
   soap_resp_msg   VARCHAR2 (2000);

   -- HTTP REQUEST/RESPONSE
   http_req        UTL_HTTP.req;
   http_resp       UTL_HTTP.resp;

BEGIN
   --
   -- Create SOAP request via HTTP
   --
   soap_req_msg :=
      '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:myschema="http://HelloEjb"> <soapenv:Header/>
  <soapenv:Body>
  <myschema:in0><myschema:message>Test Message</myschema:message></myschema:in0>
  </soapenv:Body></soapenv:Envelope>';

   http_req :=
      UTL_HTTP.begin_request
                         ('http://localhost:8080/HelloBeanService/HelloBean',
                          'POST',
                          'HTTP/1.1'
                         );
   UTL_HTTP.set_header (http_req, 'Content-Type', 'text/xml');
   UTL_HTTP.set_header (http_req, 'Content-Length', LENGTH (soap_req_msg));
   UTL_HTTP.set_header (http_req, 'SOAPAction', '');
   UTL_HTTP.write_text (http_req, soap_req_msg);

  --
   -- Invoke Request and get Response.
   --
   http_resp := UTL_HTTP.get_response (http_req);
   UTL_HTTP.read_text (http_resp, soap_resp_msg);
   UTL_HTTP.end_response (http_resp);
   DBMS_OUTPUT.put_line ('Output: ' || soap_resp_msg);
END;
/

</code>
Leave a comment

Leave a comment

  • Join 10 other subscribers
  • Tweets