You are on page 1of 30

Home Welcome Register

Articles Certifications Downloads Featured Article Forum

Consuming a Web Service in ABAP


Aug 29th, in Articles, Home, SAP ABAP, by Ajay

This is a continued part of earlier article. In this exercise we will find how we can consume a Web Service using ABAP by creating Proxy Class and Configure Logical Port.

Author : Ajay

Author's Website | Articles from Ajay

Lets start: In this exercise we will look at how we can consume a web service using a client proxy with ABAP. Why do we need a Web service Client Proxy : 1. Webservice Client Proxy acts as transfer program. 2. It is used to connect to Server of the required Web Service 3. Creation of Valid SOAP messages and evaluation of received responses is taken care by the proxy. So developer can concentrate on the Business Application without bothering about the technical aspects, that is how the SOAP messages are exchanged. CREATE PROXY CLASS : Step 1: To start the Service Wizard again, from SE80 right click and choose Create->Enterprise Service.

Step 2 : This time in the Object Type step of the Service Wizard, choose Service Consumer . As we are at consumer site.

Step 3: For the source of the Service Consumer, you can choose between the Enterprise Service Repository, a URL to a WSDL or the local file location of a WSDL, a UDDI, and the Service Registry. Please choose

URL/HTTP Destination.

Step 4: Enter the URL of WSDL file which we had created in earlier exercise.

Step 5: Fill in the necessary details in the wizard.

Step 6: On the final step, you can press Complete to start the Proxy object generation.

Step 7 : You will be promoted for your logon User name and Password.

The generated proxy class is now displayed. Click on save and activate.

SET UP LOGICAL PORT Go back to transaction SOAMANAGER and in order to setup a Logical Port for our new Service Provider. Logical Ports are used to configure runtime features of a web service. We can create a logical port by either tcode LPCONFIG(obsolete) or Soamanager as show below. Why do we need a Logical port: A consumer proxy never stores any details regarding the URl server which are specific one system. These details need to be configured through logical ports and endpoints. For example:When you transport a proxy class from a development system to production. The proxy class

doesnt hold any information about in which server the webservice needs to be called. Logical port takes care of this. Step :1 Go back to transaction SOAMANAGER and in order to setup a Logical Port for our new Service Provider. We will navigate to the same location as the last exercise the Service Administration tab and the click the link named Single Service Administration. This time when you search in the Web Service Administration, choose to Search by Consumer Proxy. Dont forget to press the Apply Selection button after highlighting your proxy. From the Configurations tab, choose Create Logical Port.

Step :2 From the Popup screen that is generated, you will have to fill in several parameters. First you will need to name your logical port and set it as the Default. Next we need to use WSDL Based Configuration. This way the application will read all the necessary security settings for calling this service directly from the WSDL definition. Finally you will again need to supply the WSDL URL for the services you are call (hopefully you still left that browser window open). You also must supply your system User name and

Password to access the WSDL.

Step :4 If successful, you will be returned to the Configuration for Logical Port screen. From here you can further define the settings for this logical port. For now we need to embed user credentials for calling this

Enterprise Service. So once again input your User name and Password and then Save the Logical Port.

TESTING You can now return to the ABAP workbench in the package ZPROXIES and the definition of your Service

Consumer and test it.

On the Test Service Consumer options dialog , choose ZSQRT Method Name. Finally execute the test.

Switch to the XML Editor and replace the number value with 16. You can go ahead and execute the request call.

The response should show the XML version of the squareroot

Now what, If you want to consume web service using ABAP. Goto SE80 and create a new report program ZPW_WEBSERVICE.

Drag and Drop the proxy class ZCO_ZWS_SQRT and you get the template for consuming. This looks like as shown below.

Modify the template for invoking the web service with the below code. REPORT zpw_webservice. DATA: proxy TYPE REF TO zco_zws_sqrt . DATA : output TYPE zzsqrt_response . DATA : input TYPE zzsqrt . input-number = 1212. TRY. CREATE OBJECT proxy EXPORTING logical_port_name = ZP00. CATCH cx_ai_system_fault . ENDTRY. TRY. CALL METHOD proxy->zsqrt EXPORTING input = input IMPORTING output = output. CATCH cx_ai_system_fault . CATCH zcx_zsqrt_exception . CATCH cx_ai_application_fault . ENDTRY. WRITE : Square root is , output-result.

Now its ready for execution. Here we go.

Obviously its not the best kind of report to build, but I hope the basics fundamentals for consuming a web service would be clear by now.

Scenario on RFC to SOAP


By Viswanadh, PI Competency Team, Yash Technologies In this blog, we will discuss on how to design and configure a scenario to use sender RFC adapter and receiver SOAP adapter.

RFC adapter in XI Adapter Engine supports Secure Network Communications (SNC). It is used to get connected to SAP R/3 system, used for synchronous communications and receive RFC messages when triggered in SAP R/3 System. SNC protects the data communication paths between the various components of the SAP System. RFC adapter converts the RFC data into RFC XML (XML message format) and send it Integration engine for further processing using the pipe line steps.

SOAP adapter in XI Adapter Engine is used to exchange SOAP message between Integration server and Web service servers. Though you can specify security settings to be used to sign/verify the message to add security to the message exchange, scenario is developed selecting HTTP as transport protocol and SOAP 1.1 as message protocol. The scenario in this posting is to trigger RFC message to XI that will send SOAP message to Web Service server to execute its method like sending a SMS to remote mobile and gets the response message and passes it to source R/3 System. Find below the step-by-step procedure to achieve this scenario: Development in R/3 System: a. RFC is created at the R/3 side with the following parameter

Designing activities in Integration Repository: 1. Enable the option import of RFC/IDOC permitted of Software component version to import RFC into XI as illustrated in below:

No need of Creating Objects for Outbound Interface when we import the RFC from R/3 system, we get the relevant Data Type, Message Type and Message Interface along with it. 2. In this scenario we are using method SendSMSToIndia from Free Web Service ofwebservicex. http://www.webservicex.net/WS/WSDetails.aspx?WSID=59&CATID=4 So, the scenario has been made interesting which would send an SMS to a remote mobile. The SendSMSToIndia Method sends the SMS to Given Mobile Number as Input parameters SendSMSToIndia Method Input parameters: Mobile Number, FromEmailAddress, Message Output information: FromEmailAddress, Mobile Number, Provider, 3. SOAP Connection parameters would be as follows: Target URL : http://www.webservicex.net/SendSMS.asmx?WSDL SOAP Action: http://www.webserviceX.NET/SendSMSToIndia Inbound Data Type State, Status

For Inbound data type, download the WSDL file SAVE as SendSMS.wsdl and create a new External Definition using the SendSMS.wsdl WSDL File

4.

Create Outbound Message Interface

5.

Create Inbound Message Interface

6.

Create Message Mapping to convert RFC structure to Web Service Request

7.

Create another Message Mapping to convert Web service Response to RFC Response

8.

Create Interface Mapping

Save the objects and activate them.

Configuration activities in Integration Directory: 1. Configure Sender RFC communication channel

Note: As soon as you create Sender RFC communication channel, save and activate it. Immediately now create a RFC destination in R/3 System of type TCP/IP with server registered program as mentioned in this communication channel against Program ID. Remember first activate then create RFC destination in R/3 system. 2. Configure Receiver SOAP communication Channel.

3.

Configure sender agreement

4.

Configure receiver agreement

5.

Configure Interface determination

6.

Configure Receiver Determination

7.

Save them and activate.

Testing the scenario: 1. Run the Function Module in SE37 in R/3 System which will send RFC message to XI

Using RFC sender adapter the message is converted to RFC XML and then routed to Integration server for Receiver determination, Mapping and routing to SOAP adapter in adapter engine.

SOAP adapter sends SOAP message to web service method which will execute to send a message to remote Mobile in this case. Response message is sent to XI and there after it retraces to RFC which would be waiting for the response. There by it is going to be synchronous processing of the message.

You might also like