<?php if (!isset($_SERVER['HTTP_SOAPACTION'])) { echo '<h3>This is a SOAP endpoint. Nothing to see here...</h3>'; exit; } class MySpecial_Server extends SoapServer { function __construct() { parent::__construct(null, array( 'uri' => 'http://www.foobar.com/', 'encoding' => 'utf-8', ) ); $this->setClass(__CLASS__); // setObject() if there already is an instantiated object to use } function ping() { return 'pong!'; } function someFunction($param1, $param2) { return true; // or false on error } // add Soap-Functions here! } $server = new MySpecial_Server(); $server->handle(); ?>
<?php class MyAlsoSpecial_Client extends SoapClient { protected $url; function __construct($url) { parent::__construct(null, array( 'location' => $url, 'uri' => 'http://www.foobar.com/', 'encoding' => 'utf-8', 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 8, ) ); $this->url = $url; } function getURL() { return $this->url; } } $client = new MyAlsoSpecial_Client('http://www.foo.com/bar/specialserver.php'); echo 'ping? ' . $client->ping(); // will output 'pong!' if connection works if ($client->someFunction('foo', 'bar')) echo 'It works!'; ?>