用PHP写和调用webservice最简单方法。

20690阅读 0评论2012-08-15 cnljh
分类:系统运维

服务端代码  文件名mainservice.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();

?>


调用端代码 


try{

//第一个参数是wsdl文件,不使用的话用null,location表示webservice服务文件的地址,uri要用要调用的webserivce中的uri一致

$client=new SoapClient(null,array('location'=>'','uri'=>'textphpwebservice'));

echo $client->sayhello("lijh")."
"
;

echo $client->mymin(100,50)."ccccc";

}catch(SoapFault $fault){

echo "fail";

}


exit();

?>

上一篇:GPS中各种参数的数据类型参考。
下一篇:postgresql的集群