Oracle9i调用WebService

来源:互联网 发布:mac更换输入法 编辑:程序博客网 时间:2024/05/01 18:11

需要在Oracle9i中调用WebService,在网上搜到一片文章,带有如下实例代码:

CREATE OR REPLACE FUNCTION WS_QUOTE( symbol in varchar2) RETURN sys.xmltype
as
    env       VARCHAR2(32767);
    http_req  utl_http.req;
    http_resp utl_http.resp;
    resp      sys.xmltype;
    in_xml    sys.xmltype;
    url       varchar2(2000):='http://www.webservicex.net/stockquote.asmx?WSDL';
  BEGIN
--    generate_envelope(req, env);
    env:='<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetQuote xmlns="http://www.webserviceX.NET/">
      <symbol>' || symbol || '</symbol>
    </GetQuote>
  </soap:Body>
</soap:Envelope>';
    http_req := utl_http.begin_request(url, 'POST','HTTP/1.1');
    utl_http.set_body_charset(http_req, 'UTF-8');
--   utl_http.set_proxy('proxy:80', NULL);
--   utl_http.set_persistent_conn_support(TRUE);
--   UTL_HTTP.set_authentication(http_req, '', '3', 'Basic', TRUE );
    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', 'http://www.webserviceX.NET/GetQuote');
    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);
    in_xml := sys.xmltype.createxml(env);
    resp := xmltype.createxml(env);
    dbms_output.put_line('same output');
    dbms_output.put_line(SUBSTR(env, 1, 245));
    RETURN resp;
  END;

修改相应的信息,测试,总是运行到utl_http.write_text(http_req, env);时报错,提示已经运行到文件尾部,看来是返回信息没有得到。查了不少资料,还是Oracle的官方文档中找到答案,建议如果需要在Oracle中调用WebService的朋友,一定看一下下面这篇文章http://www.oracle.com/technology/global/cn/tech/webservices/htdocs/samples/dbwebservice/DBWebServices_PLSQL.html

阅读一定要仔细呦。

我这的问题就是需要把'HTTP/1.1',改成“HTTP/1.0”,Oracle 9i不支持HTTP/1.1

原创粉丝点击