PLSQL 调用 Webservice 的实例

PLSQL 调用 Webservice 的实例 2012-11-02 15:57:34
分类: Linux
这是为项目写的一个封装包,用来调用一个测试用的Webservice.中间出现一些问题:
1.总是报无法取得http 头Soapaction的值的错,后来搞了半天,加了这两句解决:
Scott.Utl_Dbws.Set_Property(L_Call, 'SOAPACTION_USE', 'TRUE');
Scott.Utl_Dbws.Set_Property(L_Call, 'SOAPACTION_URI', Pi_Soap_Url);

2.发现返回的XML数据存在乱码,导致用XMLTYPE.extract().getstringval()来解析XML时发生错误,这应该是Webservice设置的问题。目前正在解决。

3.封装包所需的这些参数,基本都可以在 http://xxxx?WSDL 这种地址的页面上找到。

--调用服务
create or replace PROCEDURE call_webservice(pi_wsdl_url IN VARCHAR2,
pi_namespace IN VARCHAR2,
pi_service_name IN VARCHAR2,
pi_port_name IN VARCHAR2,
pi_operation_name IN VARCHAR2,
pi_soap_flag IN VARCHAR2,
pi_soap_url IN VARCHAR2,
pi_parameter IN VARCHAR2,
po_result OUT sys.xmltype) IS

l_service scott.utl_dbws.service;
l_call scott.utl_dbws.call;
l_wsdl_url VARCHAR2(2000);
l_namespace VARCHAR2(2000);
l_service_name scott.utl_dbws.qname;
l_port_name scott.utl_dbws.qname;
l_operation_name scott.utl_dbws.qname;
l_xmltype_in sys.xmltype;
l_xmltype_out sys.xmltype;

BEGIN
l_wsdl_url := pi_wsdl_url;
l_namespace := pi_namespace;
l_service_name := scott.utl_dbws.to_qname(l_namespace,
pi_service_name);
l_port_name := scott.utl_dbws.to_qname(l_namespace, pi_port_name);
l_operation_name := scott.utl_dbws.to_qname(l_namespace,
pi_operation_name);

--create service
/*L_Service := Scott.Utl_Dbws.Create_Service(Wsdl_Document_Location => Urifactory.Geturi(L_Wsdl_Url),
Service_Name => L_Service_Name);*/

--第二种方式
l_service := scott.utl_dbws.create_service(service_name => l_service_name);

--call webservice
/*L_Call := Scott.Utl_Dbws.Create_Call(Service_Handle => L_Service,
Port_Name => Null,
Operation_Name => L_Operation_Name);*/

--第二种方式
l_call := scott.utl_dbws.create_call(service_handle => l_service);


--设定地址
scott.utl_dbws.set_target_endpoint_address(l_call, l_wsdl_url);


--setup http soap action
IF pi_soap_flag = 'Y' THEN
scott.utl_dbws.set_property(l_call, 'SOAPACTION_USE', 'TRUE');
scott.utl_dbws.set_property(l_call, 'SOAPACTION_URI', pi_soap_url

);
END IF;

--send parameter
l_xmltype_in := sys.xmltype(pi_parameter);

--receive feedback
l_xmltype_out := scott.utl_dbws.invoke(l_call, l_xmltype_in);

--return feedback
po_result := l_xmltype_out;

END call_webservice;


--调用例子
Declare
Aa Sys.Xmltype;
Begin
Call_Webservice(Pi_Wsdl_Url => 'https://www.360docs.net/doc/f417284868.html,/WebService1.asmx?wsdl',
Pi_Namespace => 'https://www.360docs.net/doc/f417284868.html,/',
Pi_Service_Name => 'WebService1',
Pi_Port_Name => 'WebService1Soap',
Pi_Operation_Name => 'SendSucess',
Pi_Soap_Flag => 'Y',
Pi_Soap_Url => 'https://www.360docs.net/doc/f417284868.html,/SendSucess',
Pi_Parameter => '

Welcome
Success
',
Po_Result => Aa);

End;




相关文档
最新文档