ABAP 主动调用与被调用webservice实例

  1. 主动调用:

步骤:创建企业服务代理类—SM59配置—LPCONFIG配置逻辑端口—接口调用方法类

1.1创建企业服务代理类:

1.1.1

1.1.2

1.1.3

1.2 SM59配置  最后保存即可

1.3 LPCONFIG配置逻辑端口

   

1.4接口调用方法类

*"----------------------------------------------------------------------

*"*"本地接口:

*"  IMPORTING

*"     VALUE(INPUTCOLLECTION) TYPE  ZMIP_OSB_MIP_MIP_HQ_IMPORT_CA1

*"       OPTIONAL

*"  EXPORTING

*"     VALUE(E_TYPE) TYPE  CHAR2

*"     VALUE(E_MSG) TYPE  CHAR255

*"     VALUE(OUTPUTPARAMETERS) TYPE  ZMIP_OSB_MIP_MIP_HQ_IMPORT_CAN

*"----------------------------------------------------------------------

DATA:ESB_MIP_CO_OSB TYPE REF TO ZMIP_CO_OSB_MIP_MIP_HQ_IMPORT,

OBJ_EXCEPTION TYPE REF TO CX_AI_SYSTEM_FAULT,

L_OUTPUT TYPE ZMIP_OSB_MIP_MIP_HQ_IMPORT_CAN,

L_INPUT  TYPE ZMIP_OSB_MIP_MIP_HQ_IMPORT_CA1.

DATA: ERRORTEXT TYPE STRING.

*INPUTCOLLECTION-PAYLOAD-INPUTCOLLECTION-INPUTCOLLECTION_ITEMs

****Set the input parameter into the Request of the SOAP Object

****Create the Proxy and Clall it.

CREATE OBJECT ESB_MIP_CO_OSB.

TRY.

CALL METHOD ESB_MIP_CO_OSB->PROCESS

EXPORTING

INPUT  = INPUTCOLLECTION

IMPORTING

OUTPUT = OUTPUTPARAMETERS.

CATCH CX_AI_SYSTEM_FAULT INTO OBJ_EXCEPTION .

CALL METHOD OBJ_EXCEPTION->GET_TEXT

RECEIVING

RESULT = ERRORTEXT.

E_TYPE    = ‘E‘.

E_MSG = ERRORTEXT.

EXIT.

ENDTRY.

2.被调用

步骤:创建RFC函数—创建该函数的企业服务生产URL(WSDL)—SOAMANAGER配置

2.1

被调用代码(json格式转换):

FUNCTION ZFM_ESB_LIFNR_MAINTAIN_OL.

*"----------------------------------------------------------------------

*"*"本地接口:

*"  IMPORTING

*"     VALUE(MSGHEADER) TYPE  ZSESB_MSGHEADER OPTIONAL

*"     VALUE(INPUTCOLLECTION) TYPE  ZINPUTCOLLECTION OPTIONAL

*"  EXPORTING

*"     VALUE(OUTPUTPARAMETERS) TYPE  ZSESB_OUT_OL

*"----------------------------------------------------------------------

DATA: ZINPUTCOLLECTION TYPE ZESB_INPUT_JSON_MAINTAIN,

ZOUTPUTPARAMETERS TYPE ZSESB_OUT_LIFNR_MAINTAIN,

LS_INPUT       TYPE ZSLIFNR,

LS_INPUTJSON   TYPE STRING,

LS_OUTPUTJSON  TYPE STRING,

ERRORTEXT      TYPE STRING.

DATA: JSON_SER TYPE REF TO CL_TREX_JSON_SERIALIZER,

JSON_DES TYPE REF TO CL_TREX_JSON_DESERIALIZER.

DATA CX_TREX TYPE REF TO CX_TREX_SERIALIZATION.

DATA: OBJ_EXCEPTION TYPE REF TO CX_AI_SYSTEM_FAULT.

*  ls_inputjson = msgheader-input_json.

*  DATA:ZINPUTCOLLECTION TYPE

*  DATA:LT_ITEM TYPE ZTINPUTCOLLECTION .

DATA:LW_ITEM TYPE ZSINPUTCOLLECTION .

LW_ITEM = INPUTCOLLECTION-INPUTCOLLECTION_ITEM.

*  READ TABLE LT_ITEM INTO LW_ITEM INDEX 1.

LS_INPUTJSON = LW_ITEM-INPUT_JSON.

TRANSLATE LS_INPUTJSON  TO UPPER CASE.

REPLACE ALL OCCURRENCES OF ‘"LIFNR"‘  IN LS_INPUTJSON WITH ‘lifnr‘.

REPLACE ALL OCCURRENCES OF ‘"BUKRS"‘  IN LS_INPUTJSON WITH ‘bukrs‘.

REPLACE ALL OCCURRENCES OF ‘"EKORG"‘    IN LS_INPUTJSON WITH ‘ekorg‘.

REPLACE ALL OCCURRENCES OF ‘"KTOKK"‘    IN LS_INPUTJSON WITH ‘ktokk‘.

REPLACE ALL OCCURRENCES OF ‘"AKONT"‘       IN LS_INPUTJSON WITH ‘akont‘.

REPLACE ALL OCCURRENCES OF ‘"TITLE"‘  IN LS_INPUTJSON WITH ‘title‘.

REPLACE ALL OCCURRENCES OF ‘"NAME1"‘  IN LS_INPUTJSON WITH ‘name1‘.

REPLACE ALL OCCURRENCES OF ‘"NAME2"‘    IN LS_INPUTJSON WITH ‘name2‘.

REPLACE ALL OCCURRENCES OF ‘"SORTL"‘    IN LS_INPUTJSON WITH ‘sortl‘.

REPLACE ALL OCCURRENCES OF ‘"STRAS"‘       IN LS_INPUTJSON WITH ‘stras‘.

REPLACE ALL OCCURRENCES OF ‘"PSTLZ"‘  IN LS_INPUTJSON WITH ‘pstlz‘.

REPLACE ALL OCCURRENCES OF ‘"ORT01"‘  IN LS_INPUTJSON WITH ‘ort01‘.

REPLACE ALL OCCURRENCES OF ‘"LAND1"‘    IN LS_INPUTJSON WITH ‘land1‘.

REPLACE ALL OCCURRENCES OF ‘"REGIO"‘    IN LS_INPUTJSON WITH ‘regio‘.

REPLACE ALL OCCURRENCES OF ‘"TELX1"‘       IN LS_INPUTJSON WITH ‘telx1‘.

REPLACE ALL OCCURRENCES OF ‘"TELF3"‘  IN LS_INPUTJSON WITH ‘telf3‘.

REPLACE ALL OCCURRENCES OF ‘"TELFX"‘  IN LS_INPUTJSON WITH ‘telfx‘.

REPLACE ALL OCCURRENCES OF ‘"LANGU"‘    IN LS_INPUTJSON WITH ‘langu‘.

REPLACE ALL OCCURRENCES OF ‘"KUNNR"‘    IN LS_INPUTJSON WITH ‘kinnr‘.

REPLACE ALL OCCURRENCES OF ‘"BEGRU"‘       IN LS_INPUTJSON WITH ‘begru‘.

REPLACE ALL OCCURRENCES OF ‘"STCD3"‘  IN LS_INPUTJSON WITH ‘stcd3‘.

REPLACE ALL OCCURRENCES OF ‘"STCD5"‘  IN LS_INPUTJSON WITH ‘stcd5‘.

REPLACE ALL OCCURRENCES OF ‘"BANKS"‘    IN LS_INPUTJSON WITH ‘banks‘.

REPLACE ALL OCCURRENCES OF ‘"BANKL"‘    IN LS_INPUTJSON WITH ‘bankl‘.

REPLACE ALL OCCURRENCES OF ‘"BANKA"‘       IN LS_INPUTJSON WITH ‘banka‘.

REPLACE ALL OCCURRENCES OF ‘"BANKN"‘  IN LS_INPUTJSON WITH ‘bankn‘.

REPLACE ALL OCCURRENCES OF ‘"KOINH"‘  IN LS_INPUTJSON WITH ‘koinh‘.

REPLACE ALL OCCURRENCES OF ‘"BVTYP"‘    IN LS_INPUTJSON WITH ‘bvtyp‘.

REPLACE ALL OCCURRENCES OF ‘"BKREF"‘    IN LS_INPUTJSON WITH ‘bkref‘.

REPLACE ALL OCCURRENCES OF ‘"ZUAWA"‘       IN LS_INPUTJSON WITH ‘zuawa‘.

REPLACE ALL OCCURRENCES OF ‘"ZTERM"‘  IN LS_INPUTJSON WITH ‘zterm‘.

REPLACE ALL OCCURRENCES OF ‘"REPRF"‘  IN LS_INPUTJSON WITH ‘reprf‘.

REPLACE ALL OCCURRENCES OF ‘"ZWELS"‘    IN LS_INPUTJSON WITH ‘zwels‘.

REPLACE ALL OCCURRENCES OF ‘"WAERS"‘    IN LS_INPUTJSON WITH ‘waers‘.

REPLACE ALL OCCURRENCES OF ‘"WEBRE"‘       IN LS_INPUTJSON WITH ‘webre‘.

REPLACE ALL OCCURRENCES OF ‘"PROVZ"‘  IN LS_INPUTJSON WITH ‘provz‘.

REPLACE ALL OCCURRENCES OF ‘"ORT02"‘  IN LS_INPUTJSON WITH ‘ort02‘.

REPLACE ALL OCCURRENCES OF ‘"BRSCH"‘    IN LS_INPUTJSON WITH ‘brsch‘.

REPLACE ALL OCCURRENCES OF ‘"[‘  IN LS_INPUTJSON WITH ‘[‘.

REPLACE ALL OCCURRENCES OF ‘]"‘  IN LS_INPUTJSON WITH ‘]‘.

TRY .

"传入参数JSON=> 转换为结构

CREATE OBJECT JSON_DES.

CALL METHOD JSON_DES->DESERIALIZE

EXPORTING

JSON = LS_INPUTJSON

IMPORTING

ABAP = LS_INPUT.

ZINPUTCOLLECTION-INPUT_JSON = LS_INPUT.

CALL FUNCTION ‘ZFM_ESB_LIFNR_MAINTAIN‘

EXPORTING

MSGHEADER        = MSGHEADER

INPUTCOLLECTION  = ZINPUTCOLLECTION

IMPORTING

OUTPUTPARAMETERS = ZOUTPUTPARAMETERS.

*    CATCH cx_trex_serialization INTO cx_trex.

CATCH CX_AI_SYSTEM_FAULT INTO OBJ_EXCEPTION.

CALL METHOD OBJ_EXCEPTION->GET_TEXT

RECEIVING

RESULT = ERRORTEXT.

ZOUTPUTPARAMETERS-OUTPUT_JSON-E_TYPE    = ‘E‘.

ZOUTPUTPARAMETERS-OUTPUT_JSON-E_MESSAGE = ERRORTEXT.

EXIT.

ENDTRY.

"解析返回参数

TRY .

*      ***内表->JSON

CREATE OBJECT JSON_SER

EXPORTING

DATA = ZOUTPUTPARAMETERS-OUTPUT_JSON.

CALL METHOD JSON_SER->SERIALIZE.

CALL METHOD JSON_SER->GET_DATA

RECEIVING

RVAL = LS_OUTPUTJSON.

MOVE: ZOUTPUTPARAMETERS-ESB_FLAG TO OUTPUTPARAMETERS-ESB_FLAG,

ZOUTPUTPARAMETERS-ESB_RETURN_CODE TO OUTPUTPARAMETERS-ESB_RETURN_CODE,

ZOUTPUTPARAMETERS-ESB_RETURN_MESSAGE TO OUTPUTPARAMETERS-ESB_RETURN_MESSAGE,

ZOUTPUTPARAMETERS-BIZ_SERVICE_FLAG TO OUTPUTPARAMETERS-BIZ_SERVICE_FLAG,

ZOUTPUTPARAMETERS-BIZ_RETURN_CODE TO OUTPUTPARAMETERS-BIZ_RETURN_CODE,

ZOUTPUTPARAMETERS-BIZ_RETURN_MESSAGE TO OUTPUTPARAMETERS-BIZ_RETURN_MESSAGE,

ZOUTPUTPARAMETERS-INSTANCE_ID TO OUTPUTPARAMETERS-INSTANCE_ID.

REPLACE ALL OCCURRENCES OF ‘e_lifnr‘  IN LS_OUTPUTJSON WITH ‘"e_lifnr"‘.

REPLACE ALL OCCURRENCES OF ‘e_bankl‘  IN LS_OUTPUTJSON WITH ‘"e_bankl"‘.

REPLACE ALL OCCURRENCES OF ‘e_type‘    IN LS_OUTPUTJSON WITH ‘"e_type"‘.

REPLACE ALL OCCURRENCES OF ‘e_message‘ IN LS_OUTPUTJSON WITH ‘"e_message"‘.

*      REPLACE ALL OCCURRENCES OF ‘[‘  IN LS_OUTPUTJSON WITH ‘"[‘.

*      REPLACE ALL OCCURRENCES OF ‘]‘  IN LS_OUTPUTJSON WITH ‘]"‘.

OUTPUTPARAMETERS-OUTPUT_JSON = LS_OUTPUTJSON.

TRANSLATE OUTPUTPARAMETERS-OUTPUT_JSON  TO UPPER CASE.

CATCH CX_TREX_SERIALIZATION INTO CX_TREX.

CALL METHOD CX_TREX->GET_TEXT

RECEIVING

RESULT = ERRORTEXT.

ZOUTPUTPARAMETERS-OUTPUT_JSON-E_TYPE    = ‘E‘.

ZOUTPUTPARAMETERS-OUTPUT_JSON-E_MESSAGE = ERRORTEXT.

EXIT.

ENDTRY.

ENDFUNCTION.

原文地址:https://www.cnblogs.com/jimi520/p/12125632.html

时间: 2024-10-11 10:58:48

ABAP 主动调用与被调用webservice实例的相关文章

PHP调用Webservice实例

原文 PHP调用Webservice实例 NuSoap是PHP环境下的WebService编程工具,用于创建或调用WebService.它是一个开源软件,是完全采用PHP语言编写的.通过HTTP收发SOAP消息的一系列PHP类,由NuSphere Corporation(http://dietrich.ganx4.com/nusoap/ )开发.NuSOAP的一个优势是不需要扩展库的支持,这种特性使得NuSoap可以用于所有的PHP环境,不受服务器安全设置的影响. 方法一:直接调用 <?/***

Js 调用 WebService 实例

Html页面代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Js调用WebSer

JAVA调用WebService实例

WebService是提供特定服务的架构技术,通过标准的Web协议提供服务,其目的是保证不同平台的应用服务可以相互操作.目前比较流行的实现是使用.NET和JAVA两种语言技术,并且两种实现语言可以相互操作: 下面主要围绕通过JAVA语言来介绍Webservice的定义和调用,通过JAVA语言开发WebService的方式又分为Axis.axis2.Xfire.CXF以及JWS.每种方式实现都有各自的特点,由于本人使用CXF的方式比较熟练,而且,CFX和Spring无缝结合,所以下面重点介绍以CF

java程序调用xfire发布的webService服务(二)

在上一篇的调用xfire发布的webService服务中,我只是从服务端返回了一个字符串给客户端,却没有测试从客户端传递数据给服务端.而实际应用中一般是不太可能只出现这样的应用场景的,因此我便更进一步测试了客户端传递数据给服务端. 因为相关的jar包在上一篇已经说过,因此便不再重复说明,这次的测试步骤如下: 一.测试向服务端传递字符串(重点在第二个): 为了进一步理解服务搭建,我重新写了一个服务端服务类: 接口: package xfireTest; public interface XFire

[SAP ABAP开发技术总结]BAPI调用

目录导航 声明:原创作品,转载时请注明文章来自SAP师太博客,并以超链接形式标明文章原始出处,否则将追究法律责任!原文出自: 18.3.2.5.           调用BAPI 199 18.3.2.5.1.       BAPI事务处理... 200 18.3.2.5.2.       外部系统(Java)调用BAPI函数... 201 18.3.2.5.2.1.    直连.连接池... 201 18.3.2.5.2.2.    访问结构... 202 18.3.2.5.2.3.    访

WebService学习总结(四)——调用第三方提供的webService服务

WebService学习总结(四)——调用第三方提供的webService服务 互联网上面有很多的免费webService服务,我们可以调用这些免费的WebService服务,将一些其他网站的内容信息集成到我们的Web应用中显示,下面就以获取天气预报数据和查询国内手机号码归属地为例进行说明. 气象中心的管理系统将收集的天气信息并将数据暴露出来(通过WebService Server), 而各大站点的应用就去调用它们得到天气信息并以不同的样式去展示(WebService Client).一. 调用

C#调用Java方法(详细实例)

C#调用c++ C#调用C++的例子网上很多,以一个C++的具体方法为例. C++代码 // 获取一帧图像数据MVSMARTCAMCTRL_API int __stdcall MV_SC_GetOneFrame(IN void* handle,                                                    IN OUT unsigned char *pData ,                                               

在Android中调用C#写的WebService(附源代码)

由于项目中要使用Android调用C#写的WebService,于是便有了这篇文章.在学习的过程中,发现在C#中直接调用WebService方便得多,直接添加一个引用,便可以直接使用将WebService当做一个对象使用,利用Vs2010中的代码提示功能就能爽歪歪地把想要的东西全部点出来.在Android调用,麻烦了一点,但是也还好.主要是我们需要自己在代码中确定要调用WebService的方法名是什么,要传给WebService什么参数以及对应的参数名,另外,一些额外的信息比如soap的版本号

用C#.NET调用Java开发的WebService传递int,double问题,出现java无法获得值!

用C#.NET调用Java开发的WebService时,先在客户端封装的带有int属性的对象,当将该对象传到服务器端时,服务器端可以得到string类型的属性值,却不能得到int类型.double和DateTime类型的值(在服务端得到的均为null) 解决办法: VS2005封装WebService引用 用C#.NET调用Java开发的WebService时,先在客户端封装的带有int属性的对象,当将该对象传到服务器端时,服务器端可以得到string类型的属性值,却不能得到int类型.doub

C#通过http post方式调用需要证书的webservice

前一段时间做花旗银行的项目,用到花旗的接口是websevice,由于很多原因直接在项目中引用webservice不成功,于是就用了http post方式请求,把请求信息(xml格式)组装之后发送到服务器,返回结果. 下面就把我当时做的方法分享,希望对大家有用. 1,首先在webconfig中配置需要的信息 注:RewardUrl为url地址中公用的部分,因为后面调用不同的接口,地址是不一样的,所以就抽出来单独定义了,CommonUrl为IP+端口号,因为这个地址有可能更换所以也单独定义了. <a