Vous êtes sur la page 1sur 3

Basic Web Service Call (SAP Library - SOAP Runtime for the SAP W... http://help.sap.com/saphelp_webas620/helpdata/en/2d/64d029e74911...

Basic Web Service Call

The call of a Web Service in the SAP Web AS from external development tools such as Visual Studio
.NET was described in the previous unit Calling a Web Service from VS.NET. The following describes
how Web Services of the SAP Web AS can be called from ABAP programs.

The unit Basic Concepts describes the main components of the SOAP Runtime for the calling side – the
classes CSoapDocumentand CSoapTransportHttp of the include program SOAPINCL. This unit
uses a concrete example to describe the procedure for developing a SOAP client.

1. Creating the Application Coding

Inclusion of the include program SOAPINCL (using the include command)
Generation and filling of an instance of the SOAP document class CsoapDocument (specification of the
SOAP methods to be called and the parameters for the SOAP call).
Generation and filling of an instance of the SOAP document class CSoapTransportHttp (decision between
URL-based or destination-based call)
Transfer of the document object to the transport object
Execution of the call
Error handling
2. Optional: If you are using a destination-based call, you need to create a corresponding destination of type H
(server is a Web AS) or G (external server) in transaction SM59.
3. Testing the Program
4. Optional: If an error occurs, you can use the trace mechanisms of the ICF/ICM to perform error analysis
(mainly in transactions SMICM or SM59). For more information on analyzing errors, see Administration.

The SOAP caller program used as an example in the following is contained in detail in Appendix C
Step 1: Creating the Application Coding

First, you need to inform the main program of the ABAP classes of the client SOAP Runtime, as these do
not exist as global classes in the Class Builder (SE24). To do this, use the include command:


The SOAP Runtime, which is based on the RFC concept, works on the basis of a request/response
communication paradigm, whereby the request/response data aspect is represented by an instance of the
class CSoapDocument, and the communication aspect is represented by an instance of the class
CsoapTransportHttp. The methods and the parameters to be called are determined in the document.
The transport instance is used to determine the target system and execute the actual SOAP call. The call is
then as follows:

DATA: osoap TYPE REF TO CSoapDocument. ²-- SOAP Document Reference

CREATE OBJECT osoap. ²-- Create Object

CALL METHOD osoap->set_method ²-- Specify Method

nsprefix = ´saprfc´
nsvalue = ´CSoapConstants=>sc_rfc_function_ns´
DATA: p_requtext LIKE SY-LISEL.

1 von 3 14.01.2008 09:24

Basic Web Service Call (SAP Library - SOAP Runtime for the SAP W... http://help.sap.com/saphelp_webas620/helpdata/en/2d/64d029e74911...

GET REFERENCE OF p_requtext INTO dref.

CALL METHOD osoap->add_parameter ²-- Specify Parameter

direction = CSoapConstants=>ic_param_in
name = 'REQUTEXT'
value = dref.

Note that you need to transfer all the parameters to the document before the call. This includes the output
parameters, for example:

GET REFERENCE OF p_echotext INTO dref.

CALL METHOD osoap->add_parameter

direction = CSoapConstants=>ic_param_out
name = 'ECHOTEXT'
value = dref.

The direction of the SOAP parameter is specified using the parameter direction. The list constants
CSoapConstants=>ic_param_in, CSoapConstants=>ic_param_out and
CSoapConstants=>ic_param_inout (= in + out) are available.

Proceed as follows to execute the call:

DATA: isoap TYPE REF TO ISoapSerialize.

DATA: otransp TYPE REF TO CSoapTransportHttp.

CALL METHOD CSoapTransport=>new_http_transport ²-- Create via Factory

IMPORTING transport = otransp.
CALL METHOD otransp->set_destination_by_name ²-- Destination via SM59

isoap = osoap.
CALL METHOD otransp->set_payload ²-- Set Document
EXPORTING payload = isoap.

CALL METHOD otransp->request_response. ²-- Execute Request

First, an instance of the HTTP transport class is generated by calling a factory method, and it is then filled
with information about the target system. The example shows the approach using a destination in SM59
(you can also use the URL directly; however, the approach using the destination is preferable in real
productive programs). Afterwards, the SOAP document that has already been filled above is transferred
to this transport instance, and the call is triggered.

To provide a clearer overview, the handling of exceptions and the check whether instance generation
returns zero references has been omitted from the example. For a productive program, this is not a
recommended approach – correct error handling should take place at this point as in the example
program in Appendix C.
Step 2: Entry in SM59

The procedure is the same as that for creating RFC destinations. However, as a destination type you need
to use either type H (HTTP connection to R/3 system) or type G (HTTP connection to external server). For
more detailed documentation, see the online application help in the transactions SM59 or SICF.

2 von 3 14.01.2008 09:24

Basic Web Service Call (SAP Library - SOAP Runtime for the SAP W... http://help.sap.com/saphelp_webas620/helpdata/en/2d/64d029e74911...

If you carry out a connection test to a destination that references the inbound SOAP Runtime, you
receive a SOAP fault with the error code SOAP-ENV:Server, and an error message stating that the
SOAP document class cannot initialize the buffer. This occurs because the connection test in SM59
sends an empty HTTP Body from which the inbound SOAP obviously cannot extract a valid SOAP call.
Step 3: Testing the Program

This step is obviously application-specific. No further instructions can be provided.

Step 4: Analyzing Errors

If an error does occur in testing, and you suspect that it is an error in SOAP communication, you first need
to analyze the error messages in the possible delivered exceptions of the SOAP Runtime.

You can also use standard test programs to check whether the SOAP Runtime is actually working. The
reports RSVSOAP1 and RSVSOAP3 are suitable for this, because the called Web Services both exist as
function modules in every SAP Web AS.

If these approaches are not successful, it may help to analyze the trace files. For more information,
see Notes for Analyzing Errors.

3 von 3 14.01.2008 09:24