php无wsdl webservice服务用法

服务端:

<?php  

class test  

{  

    function add($a,$b)  

    {  

        return $a+$b;  

    }  

}  

function getUserInfo($name)  

{  

    return 'fbbin';  

}  

//实例化的参数手册上面有,这个是没有使用wsdl的,所以第一个参数为null,如果有使用wsdl,那么第一个参数就是这个wsdl文件的地址。  

$server = new SoapServer(null, array('uri' =>'http://soap/','location'=>'http://61.160.96.114.:8000/servplat/comm/serverSoap.php'));  

$server->setClass('test');    

$server->handle();  

?>

客户端:

<?php

 

try {

    $soap = new SoapClient(null, array(

        //'location'=>'http://localhost:8000/servplat/comm/serverSoap.php',

        'location'=>'http://61.160.96.114:8000/servplat/comm/serverSoap.php',

        'uri' =>'http://soap/'      

    ));   

    echo $soap->add(100,200);

} catch (SoapFault $fault){

    echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;

?>

以上程序在异地服务器上调试成功。(已增加数据库操作的例子,代码已上传本站文件service20160729.rar

原文地址:https://www.cnblogs.com/xihong2014/p/5710762.html