通过 pl/sql 块调用 Web 服务
如何通过我们知道 url、用户名和密码的 pl/sql 块调用 Web 服务。
以及如何查看响应?
给出一些示例代码...
预先感谢
我使用了以下代码:
CREATE OR REPLACE FUNCTION READ_DATA_FROM_WS (url IN VARCHAR2,
username IN VARCHAR2,
password IN VARCHAR2)
RETURN CLOB
IS
req UTL_HTTP.req;
resp UTL_HTTP.resp;
DATA VARCHAR2 (2000);
data1 CLOB;
def_timeout PLS_INTEGER;
l_envelope VARCHAR2(32767);
BEGIN
req := utl_http.begin_request(url, 'POST','HTTP/1.0');
UTL_HTTP.set_authentication (req, username, password);
utl_http.set_header(req, 'Content-Type', 'text/xml');
resp := utl_http.get_response(req);
IF (resp.status_code = UTL_HTTP.http_ok)
THEN
UTL_HTTP.set_body_charset (resp, 'UTF-8');
BEGIN
LOOP
UTL_HTTP.read_text (resp, DATA);
data1 := data1 || DATA;
END LOOP;
EXCEPTION
WHEN UTL_HTTP.end_of_body
THEN
UTL_HTTP.end_response (resp);
UTL_HTTP.set_transfer_timeout (def_timeout);
WHEN OTHERS
THEN
NULL;
END;
UTL_HTTP.set_transfer_timeout (def_timeout);
ELSE
UTL_HTTP.end_response (resp);
DBMS_OUTPUT.put_line ('HTTP response status code: ' || resp.status_code);
END IF;
RETURN (data1);
END read_data_from_ws;
/
How to invoke a webservice through pl/sql block for which we know url,username and password.
And how to see the response?
Give some sample code...
Thanks in advance
I have used the following piece of code:
CREATE OR REPLACE FUNCTION READ_DATA_FROM_WS (url IN VARCHAR2,
username IN VARCHAR2,
password IN VARCHAR2)
RETURN CLOB
IS
req UTL_HTTP.req;
resp UTL_HTTP.resp;
DATA VARCHAR2 (2000);
data1 CLOB;
def_timeout PLS_INTEGER;
l_envelope VARCHAR2(32767);
BEGIN
req := utl_http.begin_request(url, 'POST','HTTP/1.0');
UTL_HTTP.set_authentication (req, username, password);
utl_http.set_header(req, 'Content-Type', 'text/xml');
resp := utl_http.get_response(req);
IF (resp.status_code = UTL_HTTP.http_ok)
THEN
UTL_HTTP.set_body_charset (resp, 'UTF-8');
BEGIN
LOOP
UTL_HTTP.read_text (resp, DATA);
data1 := data1 || DATA;
END LOOP;
EXCEPTION
WHEN UTL_HTTP.end_of_body
THEN
UTL_HTTP.end_response (resp);
UTL_HTTP.set_transfer_timeout (def_timeout);
WHEN OTHERS
THEN
NULL;
END;
UTL_HTTP.set_transfer_timeout (def_timeout);
ELSE
UTL_HTTP.end_response (resp);
DBMS_OUTPUT.put_line ('HTTP response status code: ' || resp.status_code);
END IF;
RETURN (data1);
END read_data_from_ws;
/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经使用 pl/sql 的 Web 服务没有问题!
我正在使用这个(+我自己的改进):http://www.oracle-base.com/dba/miscellaneous/soap_api.sql" rel="nofollow">http://www.oracle-base.com oracle-base.com/dba/miscellaneous/soap_api.sql
确保正确定义名称空间,我认为您应该只使用它来检索 ASCII 而不是二进制数据...
I have used web services with pl/sql without problems!
I'm using this one (+ my own improvements): http://www.oracle-base.com/dba/miscellaneous/soap_api.sql
Be sure that you define name spaces correctly, and I think you should only use this for retrieving ASCII not binary data...
这是一些示例代码。遗漏了一些内容,但它给了你一个想法。该函数返回 WMS Web 服务的功能 XML。
Here is some sample code. Left some pieces out but it gives you an idea. The function returns the capabilities XML for a WMS webservice.
即使有办法做到这一点,这也是一个非常糟糕的做法!
而且,这里还存在很多问题。这项服务会返回什么?您如何将结果解析为 sql 可以理解的内容?您将如何处理从服务返回的错误?
只需返回返回应用程序所需的任何内容并让应用程序调用 Web 服务即可。
Even if there is a way to do this it would be a very bad practice!
Also, there are so many problems here. What will this service return? How are you gonna parse the results to something that sql can understand? How are you going to handle errors coming back from the service?
Just return whatever it is you need to return to the application and have the app invoke the web service.