PHP SOAP 使用示例

来源:互联网 发布:网页秒杀软件 编辑:程序博客网 时间:2024/05/20 14:26

soap_client.php

<?phptry {    $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);    }}?>

访问:http://localhost/soap_client.php

0 0