WebService应用-ABAP实例:ABAP调用外部WebService

来源:互联网 发布:项目数据分析师培训 编辑:程序博客网 时间:2024/06/09 00:58

TCode:se80

选择 Package,输入我们自己的开发包,后回车

右击 开发包名称,选择菜单

出现创建向导窗口

选择”Service Consumer”,点击 继续

选择”external WSDL”,点击继续

选择”URL”,点击继续

输入WebService的WSDL地址,就是WebService地址的后面加上?wsdl这个参数。点击继续

选择开发类和创建传输号,点击继续。

点击”Complete” ,出现WebServer代理类的创建窗口。

修改系统产生的代理类的名字,然后点保存,激活。到这一步,WebService代理就创建完成了。要想使用它,我们还要创建一个逻辑端口,事务码:lpconfig。

在 代理类中选择、输入上面创建的代理类,在逻辑端口中输入端口号,PS 端口号可以随便字母和数字组合。输入描述后,点创建。

在”URL”处,输入要访问的WebService的地址,全局设置中的”状态管理”要勾上。

选择 WebService中的函数,并输入函数的SoapAction,点保存。逻辑端口创建完成。接下来就该Coding了。

*&———————————————————————*
*& Report  ZWEBSERVICETEST
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT  zwebservicetest.
DATA:helloworld(200) TYPE c.
DATA:webservice TYPE REF TO zco_web_service1soap.      “WebService代理类
DATA:gt_input TYPE zhello_world_soap_in,               “输入参数
gt_output TYPE zhello_world_soap_out.             “输出参数
DATA:lo_sys_exception   TYPE REF TO cx_ai_system_fault,
lo_app_exception   TYPE REF TO cx_ai_application_fault.
START-OF-SELECTION.
TRY.
CREATE OBJECT webservice
EXPORTING
logical_port_name  = ‘LZP101′ .                 “为此WebService创建的逻辑端口。
CATCH cx_ai_system_fault .
MESSAGE ‘出错了’ TYPE ‘S’.
ENDTRY.
TRY.
CALL METHOD webservice->hello_world
EXPORTING
input  = gt_input
IMPORTING
output = gt_output.
CATCH cx_ai_system_fault INTO lo_sys_exception .
“message ‘出错了 systemai’ type ‘S’.
WRITE lo_sys_exception->errortext.
CATCHcx_ai_application_fault INTO lo_app_exception .
WRITE / .
WRITE lo_app_exception->textid.
ENDTRY.
WRITE gt_output-hello_world_result.


转载自:http://www.beisibo.com/thread-567-1-1.html




原创粉丝点击