zoukankan      html  css  js  c++  java
  • PHP操作Webservice

    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;
    }
    ?>
  • 相关阅读:
    nginx常用配置
    docker 启动常用容器命令
    win10 安装 docker
    Selenium IDE for Google Chrome
    Python use goto statement
    TCP:一个悲伤的故事
    gtx770测评
    三十而立——年终总结
    bilibili自定义调整视频播放速度
    linux-安装docker
  • 原文地址:https://www.cnblogs.com/zhaobijin/p/5813366.html
Copyright © 2011-2022 走看看