作者:常依sunrise | 来源:互联网 | 2018-03-22 22:24
php SOAP例子(web servers)
2010-06-23 14:08:24| 分类: php笔记 |字号 订阅
php 先要开启 php_soap模块
一。
方法1
服务器端 文件叫 server.php
"http://10.10.10.24/"));//输入本台服务器的ip地址
$soap->addFunction('say'); //添加输出函数
$soap->addFunction(SOAP_FUNCTIONS_ALL); //不要忘了这个
$soap->handle(); //注意
function say($sth){
return $sth;
}
?>
客户端 输出的是 hello world
"http://10.10.10.24/server.php",'uri' =>"http://10.10.10.24/")
);
echo $client->say("hello world");
} catch (SoapFault $fault){
echo"Error:",$fault->faultcode,", string:",$fault->faultstring;
}
?>
二。
服务器端文件server.php:
"http://10.10.10.24/","classmap"=> $classmap));
$soap->setClass('Myclass');
$soap->handle();
class Myclass {
function say($someword){
return $someword;
}
}
?>
客 户端 输出的是 xyz world
try {
$client = new SoapClient(null,
array('location' =>"http://10.10.10.24/server.php",'uri' =>"http://10.10.10.24/")
);
var_dump($client);
echo $client->say("xyz world");
} catch (SoapFault $fault){
echo"Error:",$fault->faultcode,", string:",$fault->faultstring;
}
"http://localhost/webserver/soapserver.php",'uri'=>'http://127.0.0.1/'));
$soap = new SoapClient(null,array('location'=>"http://localhost/webserver/soapserver.php",'uri'=>'test'));
//两种调用方式,直接调用方法,和用__soapCall简接调用
$result1 = $soap->getName();
$result2 = $soap->__soapCall("getName",array());
echo $result1."
";
echo $result2;
}catch(SoapFault $e){
echo $e->getMessage();
}catch(Exception $e){
echo $e->getMessage();
}
?>
"http://localhost/Test/MyService/Server.php"));
//下面两种方式均可以工作,只要指定了相应的uri
//$s = new SoapServer(null,array("uri"=>"http://127.0.0.1/"));
$s = new SoapServer(null,array("uri"=>"test"));
$s -> setClass("PersonInfo");
$s -> handle();
?>