webservice 简单示例代码

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();

 

[转自http://blog.chinaunix.net/uid-20804770-id-3313306.html]

posted @ 2016-10-14 19:45  yikai.shao  阅读(215)  评论(0编辑  收藏  举报