PHP webservice入门笔记

17. January 2017 PHP 0

———————————————–Personinfo.php

<?php
Class PersonInfo
{
public function getName(){
return “My Name is lijian”;
}
}
?>

———————————————–Server.php

<?php
require_once(‘PersonInfo.php’);
$s = new SoapServer(null,array(“location”=>”http://localhost/test/Server.php”,”uri”=>”Server.php”));
$s -> setClass(“PersonInfo”);
$s -> handle();
?>

———————————————–index.php

<?php
try {
$soap = new SoapClient(null,array(‘location’=>”http://localhost/test/Server.php”,’uri’=>’Server.php’));
$result1 = $soap->getName();
$result2 = $soap->__soapCall(“getName”,array());
echo $result1.”<br/>”;
echo $result2;

} catch (SoapFault $e) {
echo $e->getMessage();
}
catch(Exception $e){
echo $e->getMessage();
}

?>