Techie
Techie

Reputation: 45124

PHP Request To Fetch Data From WSO2 Data Services Server

I have successfully set up the WSO2 Data Services Server and have created to some procedures which fetch the data as XML. I can see them in the DSS admin panel. In order to do that I have completed DSS wizard which allows me to add new data sources and created some procedures as well. That's fine.

What I want to know is how can I connect PHP with the DDS ? In other words How can I make a PHP request so that data are fetch to my PHP script from the DSS ? Is it possible to data to be fetched as JSON ? If so how ?

Upvotes: 0

Views: 485

Answers (2)

Roman Kh
Roman Kh

Reputation: 2735

This simple script might give you an idea how to connect to your server:

<?php
$client = new SoapClient("http://*yourDSserver*:*yourPort*/services/yourDSservice?wsdl",array('trace' => 1));

try { 
  $info = $client->__soapCall("op_name",array(*--your request data goes here--*));

} catch (SoapFault $fault) { 
  print($fault); 
} 

print_r($info);

change yourDSserver, yourDSport,yourDSservice, as well as op_name to values suitable for your installation.

A few more lines that might be usefull for debugging:

echo "\nRequest:\n" . $client->__getLastRequest() . "\n";
echo "\nResponse:\n" . $client->__getLastResponse() . "\n";

Upvotes: 1

Anjana Fernando
Anjana Fernando

Reputation: 614

To access the data service from PHP, there are many approaches. The first one would be to use a SOAP client of PHP to access the data services. The data service endpoint URLs are mentioned in the service dashboard of the service, for you to use as the SOAP endpoint. Also, if you want to access it RESTfully, you can create data service "resources", where you can use access the created HTTP paths, as configured. JSON is also supported, and you can use this as a reference on how to do that. Also, basically if that approach is not suitable, you can use WSO2 ESB to mediate the JSON requests to remove the XML namespaces and so on and get the JSON payload in the way you want. A sample on how to do that is shown here.

Cheers, Anjana.

Upvotes: 0

Related Questions