SAP 能通过设置WebService与外部的webservice服务连接;
1、进入事务:SE80,选择 Package ,指定保存的开发包,如图,创建一个Enterprise Service
2、在弹出的下一个窗口中选择‘URL/HTTP Destination’,点击‘继续’;
3、在弹出的窗口中,选择‘URL’,并输入wdsl地址;
4、在弹出的窗口中,在'Package'栏中输入所需保存的开发类,若保存为本地开发类,则需将‘Local/Object’选上;
5、点击完最终的‘Complete’后,如果相连接的WDSL没有问题,则会出现WebService 代理类的创建窗口;
6.lpconfig 配置逻辑端口
在进入创建端口的界面后,输入描述,并在‘一般设置’下的‘调用参数’页签中,在'URL'中输入WSDL地址,并在‘应用程序特定设置’的‘全局设置’页签下将‘状态管理’勾上,否则在激活的时候会提示‘激活不成功’;
可以通过填写 URL 的 方式,也可以通过 http 目标的方式,这个地方就是 sm59 里 RFC 的名字.
7、操作:右侧SOAP操作,输入xml文件中soapAction等号后的内容,包括引号,有可能仅仅只是两个引号
8、在事务SM59中定义一个指向BB1系统的R3类型的RFC连接(连接类型3)。
例:作用:将内表转成 json 字符串并发送.
MOVE-CORRESPONDING gt_item TO lt_kv.
DATA :rv_proxy TYPE REF TO zco_inter_face,
y_exp TYPE zexecute_web_services_request,
y_imp TYPE zexecute_web_services_response.
DATA: serializer TYPE REF TO cl_trex_json_serializer,
lv_json TYPE string.
DATA:o_return5 TYPE string .
DATA: lo_writer TYPE REF TO cl_sxml_string_writer,
lv_output_length TYPE i,
lt_binary_tab TYPE STANDARD TABLE OF sdokcntbin,
lv_jsonx TYPE xstring.
CLEAR lv_json .
lo_writer = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).
CALL TRANSFORMATION id SOURCE text = lt_kv[] RESULT XML lo_writer.
lv_jsonx = lo_writer->get_output( ).
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_jsonx
IMPORTING
output_length = lv_output_length
TABLES
binary_tab = lt_binary_tab.
CALL FUNCTION 'SCMS_BINARY_TO_STRING'
EXPORTING
input_length = lv_output_length
IMPORTING
text_buffer = lv_json
output_length = lv_output_length
TABLES
binary_tab = lt_binary_tab.
DATA str1 TYPE string.
DATA str2 TYPE string.
DATA str3 TYPE string.
DATA str4 TYPE string.
CLEAR:str1,str2,str3,str4 .
SPLIT lv_json AT '[' INTO str1 str2.
SPLIT str2 AT ']' INTO str3 str4.
CONCATENATE '[' str3 ']' INTO o_return5 .
CLEAR:y_exp,y_imp.
TRY.
CREATE OBJECT rv_proxy
EXPORTING
logical_port_name = 'LZP01'.
"为此webservice创建的逻辑端口。
CATCH cx_ai_system_fault .
MESSAGE '出错了' TYPE 'E'.
ENDTRY.
y_exp-method_para = o_return5 .
y_exp-method_name = 'tldErpManagerWebGXService'.
TRY .
CALL METHOD rv_proxy->execute_web_services
EXPORTING
execute_web_services_request = y_exp
IMPORTING
execute_web_services_response = y_imp.
CATCH cx_ai_system_fault .
IF y_imp-execute_web_services_return EQ '0'.
MESSAGE '执行成功' TYPE 'S'.
ENDIF.
CATCH cx_ai_application_fault .
IF y_imp-execute_web_services_return EQ '1'.
MESSAGE '执行失败' TYPE 'S'.
ENDIF.
ENDTRY.