I'm a beginner of developing Drupal,and I made a web service soap server module in Drupal7,it's my first web service module in Drupal. But this module occurs a error ,got the error message shows : "Sorry an error was caught executing your request: Call to undefined function db_select()" . please give me a help to fix this problem , or give me a full example to build and call a web service module with SOAP (including server and client) in Drupal7 . Thank you very much !
1. The server code :
<?php
ini_set("soap.wsdl_cache_enabled","0");
$server = new SoapServer("test.wsdl");
$server->addFunction("getCountry");
$server->handle();
function getCountry() {
$query = db_select('country', 'c');
$query->addField('c', 'id');
$query->addField('c', 'name');
$query->addField('c', 'abbreviation');
$query->orderBy('id');
print " soap_server.php method getCountry() query : ". $query->__toString();
$result = $query->execute()->fetchObject();
$i = 0;
$doc = new DOMDocument('1.0', 'UTF-8');
$doc -> formatOutput = true;
$countries = $doc->appendChild($doc -> createElement('countries'));
foreach ($result as $row) {
$country = $doc->createElement("country");
$id = $doc->createAttribute("id");
$id -> appendChild($doc->createTextNode($row->id));
$country -> appendChild($id);
$name = $doc->createAttribute("name");
$name -> appendChild($doc->createTextNode($row->name));
$country -> appendChild($name);
$abbreviation = $doc->createAttribute("abbreviation");
$abbreviation -> appendChild($doc->createTextNode($row->abbreviation));
$country -> appendChild($abbreviation);
$countries->appendChild($country);
$i++;
}
$count = $doc->createAttribute("count");
$count -> appendChild($doc->createTextNode($i));
$countries -> appendChild($count);
return $doc->saveXML();
}
2. the client code :
function test_soap_client(){
$client = new SoapClient("http://10.31.22.201/drupal7/sites/all/modules/custom/webservices/test/ws...");
try {
$result_country = $client->getCountry();
print "$result_country";
} catch(SoapFault $e) {
print "Sorry an error was caught executing your request: {$e->getMessage()}";
}
}