Consume a Web Service in ABAP

本文介绍如何在ABAP环境中使用Web服务,包括创建客户端代理、配置逻辑端口及测试Web服务调用等步骤。此外,还提供了一个具体的示例,展示了如何通过ABAP函数模块来调用Web服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转贴地址: http://www.netweavercentral.com/index.php/2011/consume-a-web-service-in-abap/

It is impossible to implement all of the necessary functions associated with a complex business problem in the same component or even technology. A modern enterprise infrastructure system must be in the position  to integrate functions in one effective process. Until now, the combination of different applications have been developed using point-to-point solutions which grow complex and impossible to maintain over time.

Web Services simplify the heterogeneous nature of most mature enterprise system landscapes. They enable you to combine functions in a single process, even if they are implemented in widely differing software components. Web services are standalone, executable entities that can be published, searched for, and called, across a network.

To consume a web service via the ABAP engine,  you  need to do the following:

  • Create a Client Proxy
  • Create a Logical Port

The creation of a proxy for the Web service in the ABAP Workbench using a WSDL document can be done in a few clicks. Once the proxy has been created a logical portal will be needed. Once those two tasks are completed, the Web Service can be called via a standard API.

Setup Information

URL:  http://www.deeptraining.com/webservices/wsStrings.asmx?WSDL

Note that SAP only supports WSDL 1.1 ( at least from what I can tell )

Create Client Proxy

You can generate client or server proxies in ABAP to send or receive messages. You generate client proxies in this example. The client proxy will provide an abstraction to the complexities of the web service.

TCODE: SE80


Click on EDIT OBJECT


Select Enterprise Services


Enter the name of the Client Proxy (ZCG_CO_WEATHER_WS) and click the CREATE button.


Select URL/HTTP Destination and press the Continue button.

Enter the WSDL in the URL field and press the Continue button


For simplicity select Local Object and enter a value in the Prefix field. Press the Continue button.


Press the Complete button.


Remember to SAVE and then ACTIVATE you code.

Create Logical Port

You configure runtime features for Web services client proxies using logical ports.

These runtime features can be configured when the Web-service client is activated. An example of such a feature is the URL-call of the Web service, which, if applicable, must be modified by users.

TCODE: LPCONFIG


Enter the Proxy class and Logical Port name. Make sure that Default Port is selected. Click the Createbutton


Enter a description for the logical port.


Enter the WSDL URL into the URL field


Now we need to add the reference from the actual WSDL code into each operation.

Open up the WSDL in a browser and look for the following:

<wsdl:operation name=”MakeUpper”>

Below that line there will be another line that has a SOAPACTION defined in it:

<soap:operation soapAction=”http://www.deeptraining.com/MakeUpper” style=”document”/>

Copy the URL defined in that line into the SOAP Action line.


Save and then Activate the Logical Port

Test the Web Service Call

TCODE: se80

To test the web service call load the client  proxy in SE80


Click on the TEST icon


Click on the Execute button


Since the web service simply converts a string to all upper case, you can now click on the EXECUTEbutton.

Note: You can also now change the default value being sent to the web service


As you can see you can even upload an entire file


If the test is successful you will see your returned string in all Upper Case

Call the Web Service within an ABAP Function

FUNCTION Z_CG_TOUPPER_TEST.
*”———————————————————
*”*”Local Interface:
*”  IMPORTING
*”     VALUE(INPUT_PARAMETER) TYPE  STRING
*”  EXPORTING
*”     VALUE(OUTPUT_PARAMETER) TYPE  STRING
*”———————————————————
DATA: WSProxy TYPE REF TO ZCG_CO_WS_STRINGS_SOAP .
TRY.
CREATE OBJECT WSProxy .
CATCH CX_AI_SYSTEM_FAULT .
ENDTRY.
data: ls_response type ZCG_MAKE_UPPER_SOAP_OUT .
data: ls_request type ZCG_MAKE_UPPER_SOAP_IN .
ls_request-DATA = INPUT_Parameter .
TRY.
CALL METHOD WSProxy->MAKE_UPPER
EXPORTING
INPUT  = ls_request
IMPORTING
OUTPUT = ls_response .
CATCH CX_AI_SYSTEM_FAULT .
CATCH CX_AI_APPLICATION_FAULT .
ENDTRY.
COMMIT WORK.
OUTPUT_Parameter = ls_response-MAKE_UPPER_RESULT .
ENDFUNCTION.


In Android development, encapsulating a website typically refers to creating an interface that allows you to interact with the website's content without exposing its underlying implementation details or hosting the entire site within your app. This is often done using webviews and APIs. Here's a basic explanation: 1. **WebView**: WebView is a built-in component that lets you display HTML, CSS, and JavaScript content inside an Android app. You can load websites by setting the WebView's `loadUrl()` method with the desired URL. ```java WebView webView = findViewById(R.id.web_view); webView.loadUrl("https://example.com"); ``` 2. **Content Providers (optional)**: If you need to access specific data from the website, you might consider using a Content Provider to fetch that information. For instance, if the website offers JSON data, you can create a custom content provider for your app to consume. 3. **API Integration**: If the website has an API, use Android's HTTP clients like `HttpClient` or later `OkHttp`, or even better, with Retrofit for a more structured approach. This allows you to make calls to the server programmatically. 4. **Separation of Concerns**: To maintain encapsulation, separate the code responsible for interacting with the website (the "adapter" layer) from your app's core logic. This helps keep your app clean and maintainable. ```java // Using Retrofit for API integration Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.example.com/") .addConverterFactory(GsonConverterFactory.create()) .build(); ApiService service = retrofit.create(ApiService.class); Call<ApiResponse> call = service.getData(); call.enqueue(new Callback<ApiResponse>() { @Override public void onResponse(Call<ApiResponse> call, Response<ApiResponse> response) { // Handle API response } @Override public void onFailure(Call<ApiResponse> call, Throwable t) { // Handle errors } }); ``` **
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值