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

Introduction


   The purpose of this article is to help on how to implement logical ports and how to create an executable program in order to consume an abap proxy after creating a webservice in PHP and a service consumer in Enterprise Services. In order to start with this article it is necessary to first build the PHP webservice and define the service consumer in ES. This foundation is perfectly explained by Karthikeya Sastry in his great document: Creating Web service in PHP and consuming it in SAP  It is a very straightforward tutorial on how to consume PHP webservices and as always: the most complex solution is rarely the best one. After going through his document I was looking after a way to consume that service he created in an executable program. So, this tutorial is a complement to show how to configure the logical port in SOAMANAGER in a way to set it as default to be used in ABAP programs that consume the proxy developed.

Configuration of Consumer Proxies    


   The configuration of consumer proxies is implemented via logical ports. Consequently, a logical port is created based on the requirements of the provider. A logical port refers to a service endpoint that is available under a unique location in the provider system. A logical port additionally contains a runtime configuration for accessing the service endpoint. Furthermore, the port also contains the logon data that is required for calling the service methods. You can create multiple logical ports for each consumer proxy, but a logical port can only refer to one endpoint. You manage and configure consumer proxies via the SOA Management tool (Transaction SOAMANAGER). The below figure illustrates the relationship between logical ports and service endpoints. A service consumer establishes a connection by sending a call via a logical port. A logical port can send a call only to one service end- point, but a service endpoint can be called via various logical ports. 

After following the steps to develop the PHP webservice in Karthikeya Sastry tutorial you should have the below enterprise service:

PHP development


In my case the MySQL DB has the structure below and by providing the titel column as a key for the PHP report, it must return the entire row:

 

- My adjusted PHP program according to the model form the tutorial:

<?php

class MyClass{

                  function test($val){

                                    $host = "xxxx";                                  

     $user = "xxxx";

                                    $senhabd = "xxxx";

                                    $db = "cdcol";

                                   

                                    $connection = mysql_connect($host, $user, $senhabd) or die('Não foi possivel conectar: ' . mysql_error());

                                    $db = mysql_select_db($db, $connection) or die("erro database");

                                   

                                    $sql = "SELECT * FROM CDS WHERE TITEL = '".$val."'";

                                   

                                    $result = mysql_query($sql) or die(mysql_error());

                                   

                                    $tbl = mysql_fetch_array($result);

                                   

                           $nome = $tbl["interpret"];

                                   

                                    echo $nome;

                           return $nome;

                  }

}

$server = new SOAPServer('service.wsdl');

$server->setClass('MyClass');

$server->handle();

?>

-  The WSDL that I generated from the tutorial:

Configuration of Logical Port


      Go to SOAMANAGER transaction and select the service administration tab. Then choose single service configuration and search for the consumer proxy you created. Then create the logical port with the URL of your generated PHP WSDL path. Until now you can only test your proxy but you are not able to use it in your ABAP program. So, the trick here is to define this logical port as the default for your consumer proxy by checking the box ‘Logical Port is default’ as in the pictures below. You could also do that in older versions with transaction LPCONFIG although it is not advisable since it must not be used to create logical ports for proxy classes generated in versions after SAP NetWeaver 2004s. SOAMANAGER override logical ports created in transaction LPCONFIG. This means that, when two logical ports with the same name exist, the logical port created in transaction SOAMANAGER will be used. This also applies to the behavior of default logical ports. If transaction SOAMANAGER is used to create a default logical port for a particular proxy class, the default logical port created for this class with transaction LPCONFIG is no longer used.

ABAP Proxy


    Finally,  after setting the logical port as default we can consume the service in an ABAP program. According to the parameters we defined for the webservice, we provide the input structure with the key for the for the records of the MySQL DB in order to retrieve the record from the output structure and display its columns.

REPORT  Z_PROXY_O_PHP.

DATA: o_proxy TYPE REF TO ZCONSCO_SERVICE,
o_ex1
TYPE REF TO CX_ROOT,
v_val
TYPE ZCONSTEST,
v_response
TYPE ZCONSTEST_RESPONSE,
v_text1
TYPE string.

START
-OF-SELECTION.

v_val
-NEW_OPERATION_REQUEST = 'Beauty'.

TRY.
CREATE OBJECT: o_proxy.

CALL METHOD o_proxy->test
EXPORTING
input = v_val
IMPORTING
output = v_response.

commit work.

CATCH CX_AI_SYSTEM_FAULT INTO O_EX1.
V_TEXT1
= O_EX1->GET_TEXT( ).
ENDTRY.

IF v_response IS NOT INITIAL.

WRITE: v_response-NEW_OPERATION_RESPONSE.

ENDIF.

Result


According to our PHP webservice it will be displayed the second column from MySQL DB table:

2 Comments