Pergunta

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 ?

Foi útil?

Solução 2

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.

Outras dicas

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";
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top