先写一个简单的例子:
通过soap方式调用服务端的加法函数执行运算。
服务端SoapServer.php
<?
$soap = new SoapServer(null,array('uri'=>"http://127.0.0.1/"));//This uri is your SERVER ip.
$soap->addFunction('add'); //Register the function
$soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();
function add($i, $j){
$res = $i + $j;
return $res;
}
?>
客户端SoapClient.php
<?
try {
$client = new SoapClient(null,
array('location' =>"http://localhost/SoapServer.php",'uri' => "http://127.0.0.1/")
);
echo $client->add(120,5);
} catch (SoapFault $fault){
echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
}
?>
代码中的location一点要保证能够找到,我自己测试uri随便改都无所谓,
通过wsdl的方式调用的例子