PHP SOAP 使用示例

soap_client.php

    <?php  
    try {  
        $client = new SoapClient(  
            null,  
            array('location' =>"http://localhost/soap_server.php",'uri'=>"http://test-uri")  
        );  
        echo $client->getVar();  
      
    } catch (SoapFault $fault){  
        echo "Error: ".$fault->faultcode."<br/> String: ".$fault->faultstring;  
    }  

soap_server.php

    <?php  
    $soap = new SoapServer(null,array('uri'=>"http://test-uri"));  
    $soap->setClass('MyClass');  
    $soap->handle();  
    class MyClass {  
        public $var = 'Hello';  
        function getVar() {  
            return xmlrpc_encode($this->var);  
        }  
    }  
    ?>  

 

posted on 2014-07-02 15:16  文淇的技术日记  阅读(271)  评论(0编辑  收藏  举报

导航