php soap的简单用法
WSDL模式实现
第一步:编写服务端类文件
class..php
<?php
class test
{
/**
*
* @return string
*/
function show()
{
return 'hello world!';
}
}
?>
第二步:将类文件生成 wsdl文件server.wsdl。
由于wsdl文件编写比较复杂,所以我们用第三方工具生成。我们以zend studio为例子演示:
Tools ==> WSDL Generator ==> Configration name : test; WSDL file name: server
==>NEXT ==> 点击 + ==> 选择上面的创建的class.php ==> 这时候会看到一个 classes?? : URL Location的映射,保留 test类前面的勾,并将其url 设置为 SOAP Server的url:http://soapserver_url/server.php ==>点击Finish,ZDE就会创建一个非常漂亮的WSDL了?? 工作基本上完成了.
第三步:服务端编写:
<?php
require ' class..php ';//引入类文件
$server = new SoapServer('server.wsdl');
$server->setClass('test');
$server->handle();
?>
第四步:客户端编写
$soap = new SoapClient('http:// soapserver_url/server.wsdl');
print_r($soap->__getFunctions());
echo $soap->show();
页:
[1]