用PHP写和调用webservice最简单方法
2016-02-26 14:36
696 查看
服务端代码 文件名mainservice.php
<?php
//其中uri相当于java中的命名空间,可以是任何不和别人重合的字符串,第一个参数是wsdl,如果不使用wsdl则使用null,第三个参数表示soap的版本号,目前就两个版本号
$wbServer= new SoapServer(null, array('uri'=>'textphpwebservice','soap_version'=>SOAP_1_2));
$wbServer->addFunction('sayhello');
$wbServer->addFunction('mymin');
$wbServer->handle();
function sayhello($name){
return "hello ".$name."you
are great!";
}
function mymin($a,$b){
return $a>$b?$b:$a;
}
exit();
?>
客户端代码
<?php
try{
//第一个参数是wsdl文件,不使用的话用null,location表示webservice服务文件的地址,uri要用要调用的webserivce中的uri一致
$client=new SoapClient(null,array('location'=>'http://localhost/mainservice.php','uri'=>'textphpwebservice'));
echo $client->sayhello("lijh")."<br
/>";
echo $client->mymin(100,50)."ccccc";
}catch(SoapFault $fault){
echo "fail";
}
exit();
?>
<?php
//其中uri相当于java中的命名空间,可以是任何不和别人重合的字符串,第一个参数是wsdl,如果不使用wsdl则使用null,第三个参数表示soap的版本号,目前就两个版本号
$wbServer= new SoapServer(null, array('uri'=>'textphpwebservice','soap_version'=>SOAP_1_2));
$wbServer->addFunction('sayhello');
$wbServer->addFunction('mymin');
$wbServer->handle();
function sayhello($name){
return "hello ".$name."you
are great!";
}
function mymin($a,$b){
return $a>$b?$b:$a;
}
exit();
?>
客户端代码
<?php
try{
//第一个参数是wsdl文件,不使用的话用null,location表示webservice服务文件的地址,uri要用要调用的webserivce中的uri一致
$client=new SoapClient(null,array('location'=>'http://localhost/mainservice.php','uri'=>'textphpwebservice'));
echo $client->sayhello("lijh")."<br
/>";
echo $client->mymin(100,50)."ccccc";
}catch(SoapFault $fault){
echo "fail";
}
exit();
?>
相关文章推荐
- PHP正则表达式提取html超链接中的href地址
- 牛人写的facebook优化php来龙去脉
- PHP设计模式之单例模式
- php更多加载...
- PHP关于上传的有关配置
- exit()与die()在PHP中的区别
- PHP反射(ReflectionClass、ReflectionMethod)在ThinkPHP框架的控制器调度模块中的应用
- netperf的安装及使用
- SAS Macro STPBEGIN
- PHP如何实现文件上传
- Yii去掉index.php?r=
- partprobe命令用法
- php随机字符串
- php+js 瀑布流源码
- PHPExcel导入导出Excel文件
- cookie 和 session 的关系
- php 截取字符段长度 方法
- PHP文件缓存smarty模板应用实例分析
- php-fpm配置
- how to setup php running environment on osx