Upload
nageswar-vattikuti
View
221
Download
0
Embed Size (px)
Citation preview
8/12/2019 Consuming Web Service
1/20
Letsstart: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.
8/12/2019 Consuming Web Service
2/20
Step 2 : This time in the Object Type step of the Service Wizard, choose Service Consumer .As we are at consumer site.
8/12/2019 Consuming Web Service
3/20
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
8/12/2019 Consuming Web Service
4/20
URL/HTTP Destination.
Step 4: Enter the URL of WSDL file which we had created in earlier exercise.
8/12/2019 Consuming Web Service
5/20
Step 5: Fill in the necessary details in the wizard.
8/12/2019 Consuming Web Service
6/20
Step 6: On the final step, you can press Complete to start the Proxy object generation.
8/12/2019 Consuming Web Service
7/20
Step 7 : You will be promoted for your logon User name and Password.
8/12/2019 Consuming Web Service
8/20
The generated proxy class is now displayed. Click on save and activate.
SET UP LOGICAL PORTGo 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
8/12/2019 Consuming Web Service
9/20
doesnthold any information about in which server the webservice needs to be called. Logical port takes
care of this.
Step :1Go 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 theService Administration tab and the click
the link namedSingle Service Administration.This time when you search in the Web Service Administration, choose to Search by Consumer Proxy.
Dontforget to press theApply Selectionbutton after highlighting your proxy.From the Configurations tab, choose Create Logical Port.
8/12/2019 Consuming Web Service
10/20
Step :2From 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 useWSDL 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
8/12/2019 Consuming Web Service
11/20
Password to access the WSDL.
Step :4If 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
8/12/2019 Consuming Web Service
12/20
Enterprise Service. So once again input your User name and Password and then Save the Logical Port.
TESTINGYou can now return to the ABAP workbench in the package ZPROXIES and the definition of your Service
8/12/2019 Consuming Web Service
13/20
Consumer and test it.
8/12/2019 Consuming Web Service
14/20
On the Test Service Consumer options dialog , choose ZSQRTMethod 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
8/12/2019 Consuming Web Service
15/20
Now what, If you want to consume web service using ABAP.Goto SE80 and create a new report program ZPW_WEBSERVICE.
8/12/2019 Consuming Web Service
16/20
8/12/2019 Consuming Web Service
17/20
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.REPORTzpw_webservice.
DATA: proxy TYPEREFTOzco_zws_sqrt .
DATA: outputTYPEzzsqrt_response .
8/12/2019 Consuming Web Service
18/20
DATA: inputTYPEzzsqrt .
input-number= 1212.
TRY.
CREATEOBJECT proxy
EXPORTING
logical_port_name = ZP00.
CATCHcx_ai_system_fault .
ENDTRY.
TRY.
CALLMETHODproxy->zsqrt
EXPORTING
input= input
IMPORTING
output= output.
CATCHcx_ai_system_fault .
CATCHzcx_zsqrt_exception .
CATCHcx_ai_application_fault .
ENDTRY.
WRITE: Squareroot is, output-result.
8/12/2019 Consuming Web Service
19/20
Now its ready for execution. Here we go.
8/12/2019 Consuming Web Service
20/20
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.