Another simple example for SOAP_SERVER with errorhandling an params and wsdl:
SERVER (soap_all_srv.php):
<?php
require_once "SOAP/Server.php";
$skiptrace =& PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
$skiptrace = true;
class mytimeserv {
public $__dispatch_map = array ();
public function __construct() {
$this->__dispatch_map["now"] =
array ("in" => array("format" => "string"),
"out" => array("time" => "string"));
}
public function __dispatch($methodname) {
if (isset($this->__dispatch_map[$methodname])) {
return $this->__dispatch_map[$methodname];
}
return NULL;
}
function now ($format) {
if (($format == null) || (trim($format) == "")) {
return new SOAP_Fault("Kein Parameter angegeben","0815", "Client");
}
date_default_timezone_set('Europe/Berlin');
$time = date ($format);
return (new SOAP_Value('time','string', $time));
}
}
$service = new mytimeserv();
$ss = new SOAP_Server();
$ss->addObjectMap (&$service,"urn:mytimeserv");
if (isset($_SERVER["REQUEST_METHOD"])&& $_SERVER["REQUEST_METHOD"] == "POST") {
$ss->service ($HTTP_RAW_POST_DATA);
} else {
if (isset($_SERVER['QUERY_STRING']) && strcasecmp($_SERVER['QUERY_STRING'],'wsdl') == 0) {
require_once "SOAP/Disco.php";
$disco = new SOAP_DISCO_Server ($ss,"mytimeserv","My Time Service");
header("Content-type: text/xml");
print $disco->getWSDL ();
}
}
?>
CLIENT (soap_all_client.php) (for wsdl: http://example.com/soap_all_srv.php?wsdl):
<?php
require_once "SOAP/Client.php";
$sw = new SOAP_WSDL ("http://example.com/soap_all_srv.php?wsdl");
$proxy = $sw->getProxy ();
$erg = $proxy->now ("H:i:s");
print $erg."\n";
?>