ABAP proxy to Consume PHP Webservices
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:
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:
$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”];
$server = new SOAPServer(‘service.wsdl’);
– 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.
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.
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.
v_val–NEW_OPERATION_REQUEST = ‘Beauty’.
CREATE OBJECT: o_proxy.
CALL METHOD o_proxy->test
input = v_val
output = v_response.
CATCH CX_AI_SYSTEM_FAULT INTO O_EX1.
V_TEXT1 = O_EX1->GET_TEXT( ).
IF v_response IS NOT INITIAL.
According to our PHP webservice it will be displayed the second column from MySQL DB table: