SAP与外部WebService接口的链接

时间:2024-02-25 18:56:49

参考博客:http://scnblogs.techweb.com.cn/lxzwsk/archives/27.html

SAP 能通过设置WebService与外部的webservice服务连接;

1、进入事务:SE80,选择 Package ,指定保存的开发包,按图1操作,创建一个Enterprise Service;

(图1)

2、会出现如下的创建导向窗口,选择 \'Service Consumer\',点击‘继续’,如图2;

 

(图2)

3、在弹出的下一个窗口中选择‘URL/HTTP Destination’,点击‘继续’,如图3;

(图3)

4、在弹出的窗口中,选择‘URL’,并输入wdsl地址,如图4;

(图4)

5、在弹出的窗口中,在\'Package\'栏中输入所需保存的开发类,若保存为本地开发类,则需将‘Local/Object’选上,如图5;

(图5)

6、点击完最终的‘Complete’后,如果相连接的WDSL没有问题,则会出现WebService 代理类的创建窗口,如图6;

(图6)

7、在保存并激活完代理类后,进入事务:LPCONFIG,进行创建逻辑端口的操作,如图7;

(图7)

8、在进入创建端口的界面后,输入描述,并在‘一般设置’下的‘调用参数’页签中,在\'URL\'中输入WSDL地址,并在‘应用程序特定设置’
    的‘全局设置’页签下将‘状态管理’勾上,否则在激活的时候会提示‘激活不成功’,如图8;
(图8)
9、在‘一般设置’下的‘操作’页签中,在‘SOAP’操作对应的输入框中输入对应的行为地址,如图9;
(图9)
10、保存并激活逻辑端口。
11、通过编写代码来测试SAP与WebService的链接,如附件;
 
 1 *&----------------------------------------------------------------------*
 2 *&  Program  Name :  ZQIU_TEST44
 3 *&  Author\'s  Name : QLB
 4 *&  Written   Date :  25.02.2014 15:59:03
 5 *&  Request  Number:
 6 *&  Program Description:  sap 与 webservice 的连接测试
 7 *&----------------------------------------------------------------------*
 8 *  Changer           Changed Date         Request  NO.        Dec.
 9 *&----------------------------------------------------------------------*
10 
11 REPORT  zqiu_test44.
12 
13 DATA:webservice TYPE REF TO zco_oa_workflow_service.
14 
15 DATA:gw_zcreat_oa_workflow  TYPE zcreat_oa_workflow,
16      gw_input  TYPE zcreat_oa_workflow1,
17      gw_output TYPE zcreat_oa_workflow_response1.
18 
19 DATA:lo_sys_exception   TYPE REF TO cx_ai_system_fault,
20      lo_app_exception   TYPE REF TO cx_ai_application_fault.
21 
22 DATA: p_str1   TYPE string,
23       p_str2   TYPE string,
24       p_str3   TYPE string.
25 
26 
27 START-OF-SELECTION.
28 
29   "XML数据
30   p_str1 = \'<fields><field><name>Title</name><value>交办测试</value></field><field><name>Urgency</name><value>紧急</value></field>\'.
31   p_str2 = \'<field><name>YQDate</name><value>2013-09-24</value></field><field><name>Day_HF</name><value>3</value></field><field><name>XGXM</name><value>1</value></field>\'.
32   p_str3 = \'<field><name>Name_KH</name></field><field><name>Content</name><value>任务安排111</value></field><field><name>Remarks</name><value>备注111</value></field></fields>\'.
33 
34   TRY.
35       CREATE OBJECT webservice
36         EXPORTING
37           logical_port_name = \'LZP01\'.
38       "为此webservice创建的逻辑端口。
39     CATCH cx_ai_system_fault .
40       MESSAGE \'出错了\' TYPE \'E\'.
41   ENDTRY.
42 
43   "写输入参数
44   gw_zcreat_oa_workflow-arg0 = \'TW9QUQXPR74U95SS\'.
45   gw_zcreat_oa_workflow-arg1 = \'L_TYLC_GZJB\'.
46   gw_zcreat_oa_workflow-arg2 = \'\'呵呵.
47   gw_zcreat_oa_workflow-arg3 = \'\'.
48   gw_zcreat_oa_workflow-arg4 = \'admin\'.
49   gw_zcreat_oa_workflow-arg5 = |{ p_str1 }{ p_str2 }{ p_str3 }|.
50   gw_input-parameters = gw_zcreat_oa_workflow.
51 
52   TRY.
53       CALL METHOD webservice->creat_oa_workflow
54         EXPORTING
55           creat_oa_workflow          = gw_input
56         IMPORTING
57           creat_oa_workflow_response = gw_output.
58     CATCH cx_ai_system_fault INTO lo_sys_exception .
59       "“message ‘出错了 systemai’ type ‘s’.
60       WRITE lo_sys_exception->errortext.
61     CATCH cx_ai_application_fault INTO lo_app_exception .
62       WRITE / .
63       WRITE lo_app_exception->textid.
64   ENDTRY.
65 
66   WRITE gw_output-parameters-return.