Вы находитесь на странице: 1из 33

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
Ajay is a Functional Consultant in Supply Chain Management. He is a SAP Certified
SCM APO consultant and ABAP Developer. He is also involved in SAP implementations,
Migration and Support activities as a Consultant.

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.

RELATED POST

Related posts

Advertise With Us !!
Function Module EXIT in SAP ABAP with Tutorial
What is SAP HANA ?
MVC Architecture for Webdynpro for ABAP
SAP ABAP interview questions and answers
ABAP Certification : Our Journey
SAP MM Certification And Interview Questions: SAP MM Interview Questions,
Answers, And Explanations
Congratulations!!! Winners of coding challenge April 2011
SAP ALV Excel Inplace with with macro recording
Mailing Spool Details of Background job

coded by nessus

Like this post? Share it!

Related Posts

User Comments

1.

Dipankar Biswas
November 27, 2010

This is a great sample solution. Do you have one where you can publish a Function
module as a web service, so that outside application can consume sap services ?

Thanks,
Dipankar
REPLY

o
Ajay
November 27, 2010

Hi Dipankar,
Yes , Check out the following article on how to create a Webservice in 10 Mins.
Here it explains how you can expose a FM as a web service which can be consumed by
outside application.
http://sapignite.com/create-a-web-service-in-10-minutes/
Cheers
Ajay
REPLY

2.

Rodrigo Fuentes
January 10, 2011

Hello Ajay your article is very usefull to work with and i want to thanks for share this
kind of information.
Recently i create my own function module and i publishes through a ESB (BEA
Aqualogic)
Then this WS is available from one of the deploy servers of the ESB.
The problem is when i try to use the URL where the service is deployed SAP always
show a 404 error, because cannot recha the HTTP destination wich use a virtual host
Do you kno how to solve this?

Thank you very much!


REPLY

o
admin
January 14, 2011

Hi,
Its clear that the webservice URL is not accessible .
Have you verified all your settings on SICF?
Is that you are facing this problem in a particular browser only?
Thanks
Ajay
REPLY

3.

Sreejith SP
February 2, 2011

Hi,
The logical port created are not part of the transport request? I have created a logical port
in my dev system and hoped that it would also go to quality and production systems
along with the consumer proxy classes. Do we need to create the logical port manually in
all of these systems?
Thanks
Sreejith
REPLY

o
Ajay
February 2, 2011

Hi Sreejith,
You are correct.
Logical ports are not transported ,you have to create them manually in each of these
target systems.
Because logical Ports are used to configure runtime features of a web service and any
details regarding URL server which are specific to one system are never stored in the
Consumer Proxy.
Let me know if you need any other clarification.
Cheers
Ajay
ajay@sapignite.com
REPLY

4.

Jose
March 30, 2011

Hello Ajay,
Nice tutorial.
Just a question, whats the main diference between consuming a web service using this
ABAP proxy tutorial, for creating on PI/XI system the SAP to SOAP scenario.
Thanks!
REPLY

o
admin
April 1, 2011

Hi Jose,
You can submit http request to call a webservice
In case of ABAP proxy u r calling a method of proxy class
The PI system handles all conversion .
At last both handles SOAP.
Thanks
Ajay
REPLY

5.

Frank
April 5, 2011

Hi Ajay,
when using the wizard to generate a web service I find 3 options to create a consumer
service. The second one is URL/HTTP-Destination. When choosing this one, the field
for the URL is restricted to 256 characters. Is there any chance to use longer URLs (via
alias or so)?
Thanks in advance,
Frank
REPLY

6.

Hajira
April 22, 2011

Hi Ajay,
Tutorial was very helpful ,but i dont have soa manager in sap as it is not the latest version
,can u please suggest me some other way to consume a webservice.
REPLY

o
admin
April 24, 2011

Hi Arun,
You can use LPCONFIG for setting up the logical port. Rest of steps being the same.
Thanks
Ajay
REPLY

7.

hajeera
May 16, 2011

Hello Ajay,
To consume a dot net web service do we hav to create same kind of webservice in sap.
Regards,
Hajeera
REPLY

o
admin
May 16, 2011

Yes.. Its the same across all the platforms.


Cheers
Ajay
REPLY

8.

lp
July 7, 2011

Hi Ajay,
Is there any way that we can push the records fetched by web service to PSA instead of
creating a ABAP program? So that it can be loaded into datatarget?
Thanks.
REPLY

o
Ajay
July 7, 2011

Hi lp,
Yes you can do that as well.
Please check the following link which provided you step by step detail for the same
Realtime Time Data Aquisition

Cheers
Ajay
REPLY

lp
July 8, 2011

Hi Ajay,
Thank you.
We are trying to extract data from MS Sharepoint into SAP BI using sharepoint web
services. Can I check if you have done that before? Could you please shed some light on
this?
Thank you.
lp
REPLY

Ajay
July 11, 2011

I am afraid, I have very little idea on MS sharepoint. I would suggest you to post this to
SDN forum for better reach.
Thanks
Ajay
REPLY

9.

MaryM
July 13, 2011

Hi Ajay,
great blog!
One question what do I have to configure to be able to send and receive encrypted
messages. Both authentication and body?
Thanks!
MaryM
REPLY

10.

Becky Levings
August 2, 2011

Thanks Ajay, your blog is very helpful. One hitch though, I do not get the
username/password screen when I create the client proxy, so the proxy is not saved with
the authentication. My calling program will be run in the background, and does not have
the needed authentication. When I run it in the foreground, it works fine, but prompts me
for my username & password. Do you have any idea why the user/password option does
not appear when I create my proxy? Thanks,
REPLY

11.

Sudharshan
August 5, 2011

Hi Ajay,
Thank you for the great article and a time saver.
I have a problem while creating proxy using wsdl. There are some errors after I click
complete but no details on the error.
I have managed to successfully create the proxy classes in Eclipse for a Java application
using the same link as below which is also the one I use for ABAP.
http://dev6.axeda.com/webservices/services/AlarmService?wsdl
I even tried to download the same and load as a local file.
Is there any reason why this file is not acceptable in SAP but in Eclipse. Is there a setting
in SAP to ignore the validation as in Eclipse?
If it is not too much trouble could you please try to create proxy for this and see what
could be wrong.
Is there a way to validate the file and a way to find and fix the error if there is any.
Please help me point towards the right direction.
Thank you for your time.
With Kind Regards,
Sudharshan
REPLY

12.

Ed Fogarty
September 8, 2011

Thanks, this is very helpful. How does one get data from a Deep Structure?
REPLY

13.

Kris Geeraerts
September 23, 2011

Hi Ajay,

Thanks for sharing this information.


I have the same problem as Becky Levings. It works fine except that userID and
Password popup appears when executing the webservice. I was not able to give user and
pasword in the proxy. I did the logical port creation with LPCONFIG (transaction SOA
Manager does not exist). I added a security profile for user and password to the logical
port but still the popup appears. Any suggestions ?
Regards,
Kris.
REPLY

14.

Asim
October 1, 2011

Gr8 work Ajay,


I have a particular problem im trying to get a work around for with regard to webservices.
Applications built using webservices work fine but only within the network where the sap
server resides. if i try to access the same webservices from outside the network, the
webservices are not accessible. how should we configure these webservices? or do u have
any idea on any java middleware that should be used for this scenario
REPLY

15.

Loren Oldham
January 12, 2012

This example is GREAT! THANKS for posting.


I am having troubles. When I use a web service that I created with vb.net I get No
Vendor Specified when attempting to create the proxy in SE80.
I then attempted to use a public web service, calculator found here
http://service-repository.com/service/overview/877027757
The wsdl is http://soaptest.parasoft.com/calculator.wsdl

that is what I entered into SE80 and the client proxy was created, I created the logical
port in SOAMANAGER and back to SE80 to test it. When I execute it and choose any of
the methods the I get the option to change the parms and when I click Execute. It give
me a dialog that specifie No Vendor Specified
What am I doing wrong? Please help.
This is the first step for me, next step is to call the FedEx rate webservice.
REPLY

o
Ajay
January 24, 2012

Hi Loren,
Why are you getting error No Vendor Specified when consuming public webservice
for calculator?
Something wrong!!
Cheers
Ajay
REPLY

16.

Sunil
February 13, 2012

Hi Ajay,
This is very nice tutorial for beginners like me, I have one doubt
Can we use any WEBSITE which takes some input and give output, as web service, or
website site should have some attributes in order to consume it for web service?

For example. website http://www.metric-conversions.org/length/meters-to-feet.htm


takes input as meters and convert it to feet.
Can we pass the value from SAP and get the result back to SAP, if yes HOW?
REPLY

17.

Kavitha
February 24, 2012

Hi is it possible to debug an abap program or function module when it is called via ESB?
Thanks..
REPLY

o
Raj
February 24, 2012

Hi Kavitha,
Please check-out the article :
http://sapignite.com/how-to-debug-sap-rfc-background-job-update-fm-etc/
To check the log Use the transaction code : SICF to get the exact XML file which was
sent via External system.
U can use this XML file and debug it using Se80 transaction code.
Thanks & Regards,
~Raj
SAP IGnite.
REPLY

18.

Rida
February 29, 2012

Hi Ajay,
thank you alot for this usefull tutorial. When i generate the proxy i get this Error:
Exception occurred in communication framework:Error in HTTP
Framework:404conn failedhttp://localhost:53597/SQRTService/Service.svc?wsdl
my service is working and i have tested it with another tool soapUI. This Service is
made by c# and i have another service which is made by SAP and i am getting the same
error.
It will be great if u could help me.

Вам также может понравиться