Hello,
I am trying to develop a very simple SOAP server and Client in PHP. The goal is to receive content from a remote XML-document as the source.
This is what I have done so far, I need help how to extract data from an XML file instead, as it is now, from an ordinary array. This is the function found in inventory_functions.php that is fetching from an array, how can it be changed to fetch from the XML file instead? Am I on the right track, is this a SOAP setup?
function getItemCount($upc) {
// In reality, this data would be coming from a database
$items = array('12345'=>5,'19283'=>100,'23489'=>'234');
// Return the requested value
return $items[$upc];
}
This is the code for the server:
// Load the database
require 'inventory_functions.php';
// Turn off WSDL cache
ini_set("soap.wsdl_cache_enabled", "0");
// Create a new SoapServer object with inventory.wsdl
$server = new SoapServer("inventory.wsdl");
// Register the getItemCount function
$server->addFunction("getItemCount");
// Start the handle
$server->handle();
This is the code for the client:
// Turn off WSDL cache
ini_set("soap.wsdl_cache_enabled", "0");
// Create a new SOAPClient object
$client = new SoapClient("inventory.wsdl");
// Get the value for the function getItemCount with the ID of 12345
$getItemCount = $client->getItemCount('12345');
// Print the result
echo ($getItemCount);
Please help!