zhaobijin

Function:

//server:
<?php
$soap = new SoapServer(null,array(\'uri\'=>"http://192.168.1.110/"));    //This uri is your SERVER ip.
$soap->addFunction(\'minus_func\');                                                 //Register the function
$soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();

function minus_func($par){
    return "Hello,".$par;
}
?>

//client:
<?php
try {
    $client = new SoapClient(null,
        array(\'location\' =>"http://192.168.1.110/server.php",\'uri\' => "http://192.168.1.110/"));
    echo $client->minus_func(\'fangbaiyi\');

} catch (SoapFault $fault){
    echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
}
?>

Class:

//server:
<?php
    //$classExample=array();
    $soap=new SoapServer(null,array(\'uri\'=>"http://192.168.1.110"));
    $soap->setClass(\'chClass\');
    $soap->handle();
    
    class chClass
    {
        public $mes="Hello World!";
        function getName()
        {
            return $this->mes;
        }
    }
?>

//client:
<?php
try{
    $client=new SoapClient(null,array(\'location\'=>"http://192.168.1.110/server1.php",\'uri\'=>"http://192.168.1.110"));
    echo $client->getName();
}catch(SoapFault $fault)
{
    echo $fault;
}
?>

分类:

技术点:

相关文章: