码迷,mamicode.com
首页 > Web开发 > 详细

PHP操作Webservice

时间:2016-08-27 18:09:18      阅读:183      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!