tamasviktor
1/29/2018 - 10:44 AM

PHP: Super minimal example of SOAP Server and Client

PHP: Super minimal example of SOAP Server and Client

<?php
// SOAP SERVER CORE (server.php)
class MySoapServer
{
  public function getMessage()
  {
    return 'Hello,World!';
  }  
  public function addNumbers($num1,$num2)
  {
    return $num1+$num2;
  }
}

$options= array('uri'=>'http:/soap.domain.com');
$server=new SoapServer(NULL,$options);
$server->setClass('MySoapServer');
$server->handle();

// CLIENT CORE (client.php)
$options= array(
  'location' 	=>	'http:/soap.domain.com',
  'uri'		=>	''
);
$client=new SoapClient(NULL,$options);
echo $client->getMessage();  //Hello,World!
echo $client->addNumbers(3,5); //  8