0

我们如何从oracle调用asp.net webservice,我们可以有一个存储过程来调用asp.net webservice吗?

4

1 回答 1

1

这是一个简单的存储过程,它从 oracle 调用一个简单的 ASP.NET 加法 Web 服务,它为我们提供了我们从 Oracle 提供的两个数字相加的结果。

CREATE OR REPLACE PROCEDURE sp_WsAdd
(

  P_NUM1 number,
  P_NUM2 number
)
AS
V_INVELOP_TEMP VARCHAR2(32767);
V_INVELOP      VARCHAR2(32767);
V_REQUEST      UTL_HTTP.REQ;
V_RESPONSE UTL_HTTP.RESP;  
V_WSDL_URL VARCHAR2(2000):='Address of your Webservice';
V_XML XMLTYPE; 
BEGIN
    V_INVELOP:='<?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>
   <add xmlns="http://tempuri.org/">
     <num1>'||P_NUM1||'</num1>
     <num2>'||P_NUM2||'</num2>
   </add>
 </soap:Body>
</soap:Envelope>';

  V_REQUEST:= UTL_HTTP.BEGIN_REQUEST(V_WSDL_URL, 'POST','HTTP/1.1');
              UTL_HTTP.SET_BODY_CHARSET(V_REQUEST, 'UTF-8');

   UTL_HTTP.SET_HEADER(V_REQUEST, 'Content-Type', 'text/xml');
   UTL_HTTP.SET_HEADER(V_REQUEST, 'Content-Length', LENGTH(V_INVELOP));
   UTL_HTTP.SET_HEADER(V_REQUEST, 'SOAPAction', 'http://tempuri.org/add');
   UTL_HTTP.WRITE_TEXT(V_REQUEST, V_INVELOP);
   V_RESPONSE := UTL_HTTP.GET_RESPONSE(V_REQUEST);
            dbms_output.put_line('Response Received');
            dbms_output.put_line('--------------------------');                                                                                                                                                                                                                
            dbms_output.put_line ( 'Status code: ' || V_RESPONSE.status_code );
            dbms_output.put_line ( 'Reason phrase: ' || V_RESPONSE.reason_phrase );

  UTL_HTTP.READ_TEXT(V_RESPONSE, V_INVELOP);
  UTL_HTTP.END_RESPONSE(V_RESPONSE);

                V_INVELOP := REPLACE(V_INVELOP,'xmlns="http://tempuri.org/"','');
                V_XML:=  XMLTYPE(V_INVELOP);
                dbms_output.put_line('Value='||V_XML.extract('//addResult/text()').getStringVal());

   commit;

   END;
    /

此存储过程的 Web 服务是

  [WebMethod]
  public string add(int num1, int num2)
  {
    return (num1 + num2).ToString();
  }
于 2013-06-04T10:32:22.490 回答