Table of Contents

SOAP communication

Server

soapserver.php
<?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();
 
?>

Client

soapclient.php
<?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!';
 
?>

 
snippets/php/soap.txt · Last modified: 2010-01-15 14:38.12 by mbirth
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Contents powered by Club-Mate Contents powered by BassDrive.com Labelled with ICRA