首页 > Web开发 > 详细

PHP操作Webservice

时间:2016-08-27 18:07:55      阅读:298      评论:0      收藏:0      [点我收藏+]

Function:

//server:
<?php
$soap = new SoapServer(null,array(‘uri‘=>"http://192.168.1.110/"));    //This uri is your SERVER ip.
$soap->addFunction(‘minus_func‘);                                                 //Register the function
$soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();

function minus_func($par){
    return "Hello,".$par;
}
?>

//client:
<?php
try {
    $client = new SoapClient(null,
        array(‘location‘ =>"http://192.168.1.110/server.php",‘uri‘ => "http://192.168.1.110/"));
    echo $client->minus_func(‘fangbaiyi‘);

} catch (SoapFault $fault){
    echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
}
?>

Class:

//server:
<?php
    //$classExample=array();
    $soap=new SoapServer(null,array(‘uri‘=>"http://192.168.1.110"));
    $soap->setClass(‘chClass‘);
    $soap->handle();
    
    class chClass
    {
        public $mes="Hello World!";
        function getName()
        {
            return $this->mes;
        }
    }
?>

//client:
<?php
try{
    $client=new SoapClient(null,array(‘location‘=>"http://192.168.1.110/server1.php",‘uri‘=>"http://192.168.1.110"));
    echo $client->getName();
}catch(SoapFault $fault)
{
    echo $fault;
}
?>

PHP操作Webservice

原文:http://www.cnblogs.com/zhaobijin/p/5813366.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!