参考资料:
1.http://a138s.blog.163.com/blog/static/31474077201012494124536/
2个例子,第二个例子说明可以设置一个类的所有public方法供客户端调用!
2.http://blog.csdn.net/lyjtynet/archive/2008/11/04/3211741.aspx
对理论阐述清楚!本文也是按照他写的改改!还有些不明白的问题,若有大侠知之,告诉小弟!
==============================================================================
昨天学习了xmlrpc,是学zendframework一个例子时里面写的,还结合了smarty,理解了很长时间,调了很长时间才调好,有时间整理一下zendframework的资料吧,明天把xmlrpc弄个例子记这,东西忘得太快了!学东西不容易,忘东西快!![](https://i-blog.csdnimg.cn/blog_migrate/0d6c01d516b4fcb733e6ec5aa19283b0.gif)
这东西就是调用远程文件的方法,按我个人想,
==============================================================================
目录结构:
c:/php (localhost)
----soap
----server-----server2.php
----client ------client2.php
server2.php:
<?php
/*无wsdl*/
function greet($param) {
$retval = 'Hello , '.$param;
//这样包装信息,看起来似乎是value,key的形式,但是返回接收后也可以echo出来
return new SoapParam($retval, 'greetReturn');//或者直接
//return $retval;
}
function greet2($param) {
$retval = 'nihao , '.$param;
//这样包装信息,看起来似乎是value,key的形式,但是返回接收后也可以echo出来
return new SoapParam($retval, 'greetReturn');//或者直接
//return $retval;
}
class myclass{
public function makelove($mm){ //方法名要用public修饰才可以被调用到
$msg="I want to love ".$mm;
return new SoapParam($msg, 'msg');//或者直接
//return $msg;
}
}
//new 一个server实例
$server = new SoapServer(null, array('uri' => 'http://localhost/soap/server'));
//添加一个作为Web Services操作(operation)的函数
$server->addFunction('greet');//33
$server->addFunction('greet2');//34
//$server->setClass('myclass');//35
//设置一个类里面所有的public方法都可以被客户端调用,即作为Web Services操作(operation)的函数
//好像有setClass('')的操作,其他的$server->addFunction('');就失效,不知道为什么,请高人指点一二
//$soap->addFunction(SOAP_FUNCTIONS_ALL);
//加上后报错[Client] looks like we got no XML document in .....,高人路过请指点
//指示Web Service脚本开始处理进入的请求
$server->handle();
?>
client2.php:
<?php
/*无wsdl*/
try {
$client = new SoapClient(null,array('location' => 'http://localhost/soap/server/server2.php','uri' => 'http://localhost/soap/server'));
//echo $result = $client->__soapCall('greet', array(new SoapParam('chenlong', 'name'))); //或者直接
echo $client->greet("chenlong");//8
echo '<br>';
echo $client->greet2("chenlong2");//11
//echo $getmsg=$client->__soapCall('makelove', array(new SoapParam('my wife', 'name'))); //或者直接
//echo $client->makelove("my wife");//15
} catch (Exception $e)
{
printf("Message = %s/n",$e->__toString());
}
?>
访问: http://localhost/soap/client/client2.php
输出:
Hello , chenlong
nihao , chenlong2
注释server2.php里 33 ,34 ,放开35
注释client2.php里8,11,放开15
输出:
I want to love my wife