Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Paulo_Vantini
Participant

Objective


     This blog is about the implementation of provider proxies from enterprise services and consuming it through PHP SOAP Client. The communication via Web services is based on SOAP. Currently, SOAP is only supported by HTTP(S). SOAP requests are processed via the Internet Communication Framework (ICF). For this purpose, SAP NetWeaver AS ABAP uses HTTP in the ICF for the communication between consumer and provider. SAP NetWeaver AS ABAP can be used as a provider for Web services and as a consumer of Web services. The ABAP proxy runtime supports Web services for which an integration server is used as well as P2P connections via SOAP. In both cases, a consumer proxy is required to send the message to the receiver or a provider proxy that implements the desired function. By configuring an ABAP consumer, you can define whether the connection is a SOAP-based P2P connection or whether the message is supposed to be sent via the SAP NetWeaver XI protocol. In this example we´ll configure the endpoint URL to the ES provider proxy to be used as a P2P connection, so that it is possible to consume this service through PHP SOAP client. The figure below summarizes the landscape we described above:

Configuration of Provider Proxies    

  

     A service definition itself is no unit that can be called. To consume a Web service, you first have to create a runtime representation of the service definition, which is also referred to as service endpoint. The service endpoint contains the configuration settings for the Web service definition and is located on the provider system at a specific location, the so-called service endpoint URL. The consuming application uses this URL to call the configured Web service.

To create service endpoints, you can use the SOA Management tool, which can be called via Transaction SOAMANAGER.

The service endpoints allow for the following configuration settings:

  • Provider Security:  You can implement the settings for the transport guarantee (e.g., with- out transport guarantee, HTTPS, signature and encryption, etc.) and for the authentication method (e.g., no authentication, HTTP authentication via the user ID/password, X.509 SSL client certificate, logon ticket, or message authentication with SAML 1.1).
  • Web Service Addressing:  Here you can select the protocol for the Web service addressing.
  • Messaging: You can define the protocol for reliable messaging and the duration of the confirmation interval (in seconds) here. The confirmation interval is the period within which the provider must confirm to the consumer the receipt of a message.
  • Transport settings: In addition to the determined access URL, you can specify an alterna- tive access URL. If the service is not locally available (e.g., behind a firewall), you must specify the alternative path.
  • Message attachments:  You can define whether message attachments are supposed to be processed. In this case, several files can be sent with one message.
  • Operation specific: Here you can specify a SOAP action for an operation. The SOAP action is defined as a URI and transferred as an HTTP header if the Web service is called via HTTP.

     You can assign multiple service endpoints with different configuration settings to a Web service definition. This enables you to provide identical Web service definitions with different configuration settings to consumers. Services define groups of service endpoints. A service definition may include several services, which in turn may consist of several service end- points. This relationship is shown in figure below:

ES Development


     In this case, the enterprise service provider is going to be build based upon a remote function module.  This example uses the SFLIGHT tables data in order to be consumed by the PHP SOAP client. Create the FM as described in the figures below:


Create the Z_SFLIGHT FM with the parameters:

Next, create a webservice for the FM through menu->utilities. The output of the ES provider will look like:

     Activate your Service definition in the ES and go to SOAMANAGER transaction in order to create the endpoint URL. In SOAMANAGER go to service administration and search for the service you create.

     You can generate a WSDL document for each service endpoint. In contrast to the port type WSDL, which doesn’t contain configuration information yet, this WSDL document already contains the binding information. The trick here is to change the settings from ws_policy to standard, so that the WSDL can be called.

Activate your endpoint URL definition

PHP Development

     After creating the WSDL endpoint URL in SOAMANAGER, the next step is to create the client to consume this service through SOAP protocol. We´ll be using PHP since there are plenty of SOAP function libraries already developed for that purpose. The SoapClient function will consume the endpoint URL and bind it to the object $client. The simplified code is as follows:

<?php

$url = "http://pcbv:8000/sap/bc/srt/wsdl/srvc_0800279E7F2C1ED3B5F4C63E39130EA3/wsdl11/allinone/standard/docu...";

$login = "xxxx";

$pass = "xxxx";

//Call the client

$client = new SoapClient($url, array('login' => $login, 'password' => $pass, 'trace'  => true, 'exceptions' => true));

try {

              $air = 'AA';

              $flight = $client->ZSflight(array('Carrid' => $air));

            

              $value = get_object_vars($flight);

              $arrayf = array_map('objectToArray', $value);

              ?><table border="1">

              <tr>

              <td><?php echo ('Carrid');?></td>

              <td><?php echo ('Connid');?></td>

              <td><?php echo ('Price');?></td>

              <td><?php echo ('Currency');?></td>

              <td><?php echo ('Planetype');?></td>

              <td><?php echo ('Seatsmax');?></td>

              <td><?php echo ('Seatsocc');?></td>

              <td><?php echo ('Paymentsum');?></td>

              </tr>

               <?php

              foreach ($arrayf['TSflight']['item'] as $arr) {

              //echo $arr['TSflight']['item']['0']['Fldate'];

              ?>

              <tr>

              <td><?php echo $arr['Carrid'];?></td>

              <td><?php echo $arr['Connid'];?></td>

              <td><?php echo $arr['Price'];?></td>

              <td><?php echo $arr['Currency'];?></td>

              <td><?php echo $arr['Planetype'];?></td>

              <td><?php echo $arr['Seatsmax'];?></td>

              <td><?php echo $arr['Seatsocc'];?></td>

              <td><?php echo $arr['Paymentsum'];?></td>

              </tr>

<?php

}

?></table><?php

}

catch (SoapFault $e) {

              echo 'Caught an Error: [' . $e->faultcode . '] - ' . $e->faultstring;

}

function objectToArray( $object )

{

              if( !is_object( $object ) && !is_array( $object ) )

              {

                            return $object;

              }

              if( is_object( $object ) )

              {

                            $object = get_object_vars( $object );

              }

              return array_map( 'objectToArray', $object );

}

?>

     Note that this code has the functionality of conerting the object returned from the provider service to an array to be used in an HTML table display. For that purpose the function objectToArray does the conversion.

Results


     Here is the output from my eclipse IDE:

5 Comments