这是为项目写的一个封装包,用来调用一个测试用的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 这种地址的页面上找到。
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);
--call webservice
L_Call := Scott.Utl_Dbws.Create_Call(Service_Handle => L_Service,
Port_Name => Null,
Operation_Name => L_Operation_Name);
--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
Cux_Common_Utilities_Pkg .Call_Webservice(Pi_Wsdl_Url => 'http://www.jxsd999.com/WebService1.asmx?wsdl',
Pi_Namespace => 'http://tempuri.org/',
Pi_Service_Name => 'WebService1',
Pi_Port_Name => 'WebService1Soap',
Pi_Operation_Name => 'SendSucess',
Pi_Soap_Flag => 'Y',
Pi_Soap_Url => 'http://tempuri.org/SendSucess',
Pi_Parameter => '<?xml version="1.0" encoding="utf-8"?>
Welcome
Success
',
Po_Result => Aa);
End;
最近发现,环境重装后,上面的封装包无法使用了,报错,尝试了N多次,换另外一种写法,可通过,下面是新的封装包
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;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10359218/viewspace-748202/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10359218/viewspace-748202/