2014年5月7日 星期三

PHP + Apache Web Service Example

serverSoap.php  

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

    function minus_func($i, $j){
        $res = $i + $j;
        return $res;
    }
?>

clientSoap.php <?php
    //client端 clientSoap.php
    try {
        $client = new SoapClient(null,
            array('location' =>"http://localhost/webservice/serverSoap.php",'uri' => "http://127.0.0.1/")
        );
        echo $client->minus_func(100,92);

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

沒有留言:

張貼留言