It is old and can be replaced with REST API web services

In Ubuntu/Debian you can install with:

apt-get install php7.0-soap

=-=-=-=-=-=-=-=-=

 

https://www.ibm.com/developerworks/opensource/tutorials/os-php-webservice/index.html

 

PHP SOAP server

 

<?php    # amirWS.php
 
function AmirFunctionEchoo($echo){
    return "ECHO: ".$echo;
}
#The “uri” value is just an unique identification, used as the namespace for the response message. 
$server = new SoapServer(null,array('uri' => "http://localhost/res"));
$server->addFunction('AmirFunctionEchoo');
$server->handle();
 
?>

 

 

 

 

The page generator client

 

<?php   # amirWSclient.php

$echo = $_GET[‘input’];

print “<h2>Echo Web Service</h2>”;
print “<form action=’simple_client.php’ method=’GET’/>”;
print “<input name=’input’ value=’$echo’/><br/>”;
print “<input type=’Submit’ name=’submit’ value=’GO’/>”;
print “</form>”;
print “</form>”;

// SoapClient (null if non-WSDL mode is used, array());

//location is the URL of the SOAP server to send the request to, and

//uri is the target namespace of the SOAP service.  

if($echo != ”){
$client = new SoapClient(

null,

array(

‘location’ => “http://192.168.0.13/amirWS.php”,

‘uri’ => “urn://192.168.0.13/req”)

);

$result = $client->__soapCall(“AmirFunctionEchoo“,array($echo));

print $result;
}
?>

 

-=-=-=-=-=-=-=-=-

Example 2 Using class MySoapServer

 

 

<?php 

// server
class MySoapServer
{
  public function getMessage()
  {
    return 'Hello,World!';
  }
  
  public function addNumbers($num1,$num2)
  {
    return $num1+$num2;
  }
}



 

$options= array(‘uri’=>’http://localhost/test’);

$server=new SoapServer(NULL,$options);

# setClass() will automatically add all the functions from

$server->setClass(‘MySoapServer’);

# DO NOT Use addFunction()because it tells it to look for a function on its own

$server->handle();

?>

 

 

# soap client

$options= array( ‘location’ => ‘http://localhost/debug.php’, ‘uri’ => ‘http://localhost/everth’ );

$client=new SoapClient(NULL,$options);

echo $client->getMessage();

#Hello,World!

echo $client->addNumbers(3,5);

# 8

-=-=-=-=-=-

Example 3

<?php # AmirServer.php

function AmirFunc($someone) { 
   return "Hello " . $someone . "!";
} 
   $server = new SoapServer(null, 
      array('uri' => "urn://192.168.0.13/res"));
   $server->addFunction("AmirFunc");   #Using addFunction() tells it to look for a function named AmirFunc() on its own $server->handle(); ?>

 

<?php # AmirClient.php

   $client = new SoapClient(null, array(
      'location' => "http://localhost/AmirServer.php",
      'uri'      => "urn://192.168.0.13/req",
      'trace'    => 1 ));

   $return = $client->__soapCall("AmirFunc",array("nice."));
   echo("\nReturning value of __soapCall() call: ".$return);

   echo("\nDumping request headers:\n" 
      .$client->__getLastRequestHeaders());

   echo("\nDumping request:\n".$client->__getLastRequest());

   echo("\nDumping response headers:\n"
      .$client->__getLastResponseHeaders());

   echo("\nDumping response:\n".$client->__getLastResponse());
?>

 Then run AmirClient.php

 

=-=-=-=-

echo "<?php phpinfo(); ?>"

 

=-=-=-=-=-

https://www.ibm.com/developerworks/opensource/tutorials/os-php-webservice/index.html

 

 

 

Loading