Skip to content

Metabolomics Fiehn Lab

Sections
Personal tools
You are here: Home » Members » Gert Wohlgemuth » oracle » Accessing a webservice from oracle

Accessing a webservice from oracle

Document Actions
this describes how you can access a webservice using oracle 10g
the procedure which accesses a simple identification service.


CREATE OR REPLACE PROCEDURE "LOGIN"
(username IN VARCHAR2, passwd IN VARCHAR2,url IN VACHRAR2)

AS

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);

BEGIN
env := '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<authenticateUser SOAP-ENC:root="1">
<v1 xsi:type="xsd:string">' || username || '</v1>
<v2 xsi:type="xsd:string">' || passwd || '</v2>
</authenticateUser>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
';

http_req := utl_http.begin_request(url,'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','authenticateUser');
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;
END;



the code is based on a couple of online example which I found using google.
Created by zwluxx
Last modified 2006-11-16 02:10 PM
 

Powered by Plone

This site conforms to the following standards: