index.php
服务端代码
<?php $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; }
client.php
客户端代码
<?php try{ //第一个参数是wsdl文件,不使用的话用null,location表示webservice服务文件的地址,uri要用要调用的webserivce中的uri一致 $client=new SoapClient(null,array('location'=>'http://demo.web.com/index.php','uri'=>'textphpwebservice')); echo $client->sayhello("lijh")." "; echo $client->mymin(100,50)."ccccc"; }catch(SoapFault $fault){ echo "fail"; } die();