Connecting to SAP with SOAP RFC

August 20, 2014 • 4 minutes read • abap, sharpsaprfc

In previous article entitled How to enable SAP ICF in a miniSAP installation you saw that SAP has a built-in HTTP module. This module contains multiples services, where each one has it’s own interface and can be enabled or disabled depending on your needs. Each service has a corresponding ABAP Class that process the HTTP Response based on the HTTP Request. It is possible to identify the class by double-clicking at the service.

CL_HTTP_EXT_PING is the class for PING service

It is also possible to publish your own HTTP Service by creating an ABAP Class that implements IF_HTTP_EXTENSION interface and register it by using SICF transaction. But this is not the subject of this post. What your are going to see here is how to use two very useful services: sap/bc/soap/rfc and sap/bc/soap/wsdl.

When used together, these services enables you to call remote-enabled function in SAP thought HTTP protocol.

SOAP WSDL: sap/bc/soap/wsdl

This service returns the WSDL (Web Services Description Language) of a Remote-Enabled Function. This document contains all necessary information to call the function thought HTTP protocol. Many languages and programming platforms ships with helpers programs that generate code based on the WSDL file (this is commonly known as Proxy). One of the elements of the service description is called endpoint, and this is the address of the HTTP in which we need to use when calling the function.

SOAP RFC: sap/bc/soap/rfc

This is the default endpoint for bc/soap/wsdl. This is the service that really executes the function based on the HTTP Request’s body. The expected return content of this service is a XML content with the structures defined on WSDL and values returned from the function executed inside SAP.

A pratical example

Suppose you have the following function named Z_SSRT_SUM.

FUNCTION z_ssrt_sum.
*"*"Local Interface:

  e_result = i_num1 + i_num2.


When you type http://<server-name>:8000/sap/bc/soap/wsdl?sap-client=001&services=Z_SSRT_SUM in the browser, your credentials will be prompted and the response text will be the following XML.

<definitions targetNamespace="urn:sap-com:document:sap:rfc:functions" xmlns="" xmlns:s0="urn:sap-com:document:sap:rfc:functions" xmlns:xsd="" xmlns:soap="" xmlns:http="">
      <xsd:schema targetNamespace="urn:sap-com:document:sap:rfc:functions">
         <xsd:element name="Z_SSRT_SUM">
                  <xsd:element name="I_NUM1" type="xsd:int"/>
                  <xsd:element name="I_NUM2" type="xsd:int"/>
         <xsd:element name="Z_SSRT_SUM.Response">
                  <xsd:element name="E_RESULT" type="xsd:int"/>
   <message name="Z_SSRT_SUMInput">
      <part name="parameters" element="s0:Z_SSRT_SUM"/>
   <message name="Z_SSRT_SUMOutput">
      <part name="parameters" element="s0:Z_SSRT_SUM.Response"/>
   <portType name="Z_SSRT_SUMPortType">
      <operation name="Z_SSRT_SUM">
         <input message="s0:Z_SSRT_SUMInput"/>
         <output message="s0:Z_SSRT_SUMOutput"/>
   <binding name="Z_SSRT_SUMBinding" type="s0:Z_SSRT_SUMPortType">
      <soap:binding style="document" transport=""/>
      <operation name="Z_SSRT_SUM">
         <soap:operation soapAction=""/>
            <soap:body use="literal"/>
            <soap:body use="literal"/>
   <service name="Z_SSRT_SUMService">
      <documentation>SAP Service Z_SSRT_SUM via SOAP</documentation>
      <port name="Z_SSRT_SUMPortType" binding="s0:Z_SSRT_SUMBinding">
         <soap:address location="http://<server-name>:8000/sap/bc/soap/rfc"/>

See how Z_SSRT_SUM and Z_SSRT_SUM.Response elements are defined as the input and output of the Z_SSRT_SUM operation. Do the same for some other complex functions you may have in your system and note how easy it is to understand the standard of WSDL content generation.

Testing the Service with soapUI

soapUI is a well known tool used to test WebServices without any need of programming. When you import the WSDL file, it’ll automatically generate the follow HTTP Request body.

<soapenv:Envelope xmlns:soapenv="" xmlns:urn="urn:sap-com:document:sap:rfc:functions">

Change both ‘?’ to 2 and 5, and executed the request. The response will be like the following XML.

<SOAP-ENV:Envelope xmlns:SOAP-ENC="" xmlns:SOAP-ENV="">
      <urn:Z_SSRT_SUM.Response xmlns:urn="urn:sap-com:document:sap:rfc:functions">

If it does not work for you, remember to set the username and password on the left sidebar at properties group named Request Properties.


I took advantage of to change the SharpSapRfc project and splitted it into two packages named SharpSapRfc.Soap and SharpSapRfc.Plain.x86/x64.

Both projects have the same usage API, that means it is possible to swap between Plain Old RFC and SOAP RFC without any breaking change. The major difference is when the connection class is instantiated, where each connector has it’s own configuration properties.

I’ve found that the project has become well organized with two distinct implementations over the same interface. This is an example of how Oriented Object Programming can bring great benefits when used correctly.

More info and source code is available at goenning/SharpSapRfc.


Discuss on Twitter Edit on GitHub