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:

P2P_XI.png

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:

/wp-content/uploads/2014/05/1_454589.png

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:


/wp-content/uploads/2014/05/serv3_454591.png

Create the Z_SFLIGHT FM with the parameters:

/wp-content/uploads/2014/05/serv2_454598.png

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

/wp-content/uploads/2014/05/serv1_454599.png

/wp-content/uploads/2014/05/serv4_454600.png

     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.

/wp-content/uploads/2014/05/soa_454607.png

/wp-content/uploads/2014/05/soa1_454608.png

     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.

/wp-content/uploads/2014/05/soa2_454609.png

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/document?sap-client=001“;

$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:

/wp-content/uploads/2014/05/result_454616.png

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Christian Katschnig

    Dear Paulo,

    pretty nice article and pretty the same issue I have right now.

    We want to integrate third Party PHP Software (sclable.com) and had two Options. RFC or SOAP. RFC dropped out early because it will not be possible to implement on Linux.

    Therefore we focused on SOAP. The Interface is up and running in a Pilot environment. But for future I am facing the Problem that implementing the Interface on PHP side will be time-consuming.

    So I am looking for a possibility to automatically create (during design-time or even during run-time) PHP Interface based on the WSDL offered by SAP webservices.

    In your articel, Paulo, you wrote: “We’ll be using PHP since there are plenty of SOAP function libraries already developed for that purpose”.

    Would you please explain that or give me an idea which libraries you are working with?

    Are they able to automatically create PHP classes based on SAP WSDL’s?

    For the first Interface I used the SAP Scripting Tool together with Eclipse 3.1.2 on a Windows XP Client. This tool worked pretty good but will not be supported in future.

    Many thanks for your information

    Kind regards,

    Christian 

    (0) 
    1. Paulo Cesar de Biasi Vantini Post author

      Dear Christian,

      It looks quite complex interface project and SOAP seems to fit best for the scenario you have described.

      PHP SOAP Extension is already embedded into PHP>=5.0.1 for SOAP 1.1 and 1.2.

      In the above example I have used the SoapClient class to consume the endpoint operation created in SOAMANAGER.

      You have the option of using several libraries and frameworks for that purpose, for example: Nusoap, Zend_Soap, WSO2, etc.

      Depending on the case creating the interfaces on PHP side will be truly time consuming and, since much of your business logic is on the ERP side, it makes sense to have PHP as a client. One of the advantages of SOAP is that WSDLs allow you to generate servers and clients from datastructures through the execution of a script.

      There are some tools like wsdl2php which generate client code against a WSDL file.

      It uses DOM to parse the WSDL and generates PHP code out of it.

      Check it out at GitHub: https://github.com/wsdl2phpgenerator/wsdl2phpgenerator

      There is also XSD-to-PHP: https://github.com/moyarada/XSD-to-PHP

      SAP scripting tool is a useful plug-in, it is a pity it will have its support halted.

      Anyway, I hope I have helped you and answered your question.

      thanks a lot for your message,

      Best Regards.

      (0) 
      1. Christian Katschnig

        Hello Paulo,

        many thanks for information you helped me a lot.

        will check wsdl2php generator to create php classes based on our (SAP) WSDL’s.

        thanks and kind regards,

        Christian

        (0) 

Leave a Reply