callServer.php //serverSoap.php
转载
<?php
//serverSoap.php
$soap = new SoapServer(null,array('uri'=>"http://127.0.0.1/"));//This uri is your SERVER ip.
$soap->addFunction('minus_func'); //Register the function
$soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();
function minus_func($i, $j){
$res = $i - $j;
return $res;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> callServer.php </title>
<meta charset="UTF-8">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<form method="post" action="">
a:<input type="text" name="numa"><br>
b:<input type="text" name="numb"><br>
<input type="submit">
</form>
<hr><?php
//client端 clientSoap.php
$a=(isset($_POST["numa"]))?$_POST["numa"]:100;
$b=(isset($_POST["numb"]))?$_POST["numb"]:90;
try {
$client = new SoapClient(null,
array('location' =>"http://127.0.0.1/myphp/serverSoap.php",'uri' => "http://127.0.0.1/")
);
echo $client->minus_func($a,$b);
} catch (SoapFault $fault){
echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
}
?>
</body>
</html>