Link to home
Create AccountLog in
Avatar of adamhealy
adamhealyFlag for United States of America

asked on

Consuming a .NET webservice with a Oracle pl/sql function

First question is; is this possible?

Next would be what am I doing wrong. Basically I am wanting to connect to http://www.webservicex.net/usweather.asmx?wsdl in order to query the web source and return the SOAP response with the dbms_output.put_line function. I have pretty much used the example from one of the Oracle Press books as my guide but still having issues.

The code is below. Any help is greatly appreciated.
I guess my first question is, is this possible?
 
I am trying to access this webservice (http://www.webservicex.net/usweather.asmx?wsdl) with pl/sql to display the output of the SOAP msg as dbms output. The code is below. Any help with this is greatly appreciated for I am pretty new at web service stuff. Not sure what part(s) I am missing to get this to work. Thanks in advance...
 
CREATE OR REPLACE FUNCTION query_request (ZipCode in NUMBER) return XMLType
AS
	soap_request varchar2(32767);
	soap_respond varchar2(32767);
	http_req utl_http.req;
	http_resp utl_http.resp;
	resp XMLType;
	i number;
	len number;
BEGIN
	soap_request := '<?xml version = "1.0" encoding = "UTF-8"?>
		<SOAP-ENV:Envelope 
			xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
			xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
			xmlns:xsd="http://www.w3.org/2001/XMLSchema">
			<SOAP-ENV:Body>
				<ns1:query xmlns:ns1="GetWeatherReport" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
					<v_ZipCode xsi:type="xsd:decimal"='|| zipcode ||'>
					</v_ZipCode>
				</ns1:query>
 
			</SOAP-ENV:Body>
		</SOAP-ENV:Envelope>';
 
 
http_req := utl_http.begin_request('http://www.webservicex.net/usweather.asmx', 'POST','HTTP/1.0');
utl_http.set_header(http_req, 'Content-Type', 'text/xml');
utl_http.set_header(http_req, 'Content-Length', length(soap_request));
utl_http.set_header(http_req, 'SOAPAction', 'query');
utl_http.write_text(http_req, soap_request);
http_resp := utl_http.get_response(http_req);
utl_http.read_text(http_resp, soap_respond);
utl_http.end_response(http_resp);
resp := xmltype.createxml(soap_respond);
resp := resp.extract('/soap:Envelope/soap:Body/child::node()','xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"');
 
 
i := 1; 
len := length(soap_respond);
WHILE (i <= len) LOOP
dbms_output.put_line(substr(soap_respond, i, 60));
i := i + 60;
END LOOP;
RETURN resp;
END;
/ 
show errors;
 
--i get compiled successfully and no errors
--and here is the code to test it that i have been using for the output
 
DECLARE 
res XMLType;
Begin
res := query_request(89121);
end;
/

Open in new window

Avatar of harry_hendrata
harry_hendrata

What are the issues?

Did you do set serveroutput on before running:

DECLARE
res XMLType;
Begin
res := query_request(89121);
end;
/

ASKER CERTIFIED SOLUTION
Avatar of harry_hendrata
harry_hendrata

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of adamhealy

ASKER

Thanks...It worked fine once I used your suggestions.