HessianPHP

hessian其实我个人认为他不是一个webservice,只能说是类似而已。因为它不具备webservice的那些特性。它支持的语言比较多我们现在只需要研究php版本的HessianPHP就行了,下载最新版本是v2.0.3的,解压之后会得到一个src的目录,这个目录使我们需要使用的一个核心文件夹。

我们把名字重命名为HessianPHP然后分别分别放到server和client端,然后分别建立server.php和client.php文件。

server端:[code]<?php
include_once ‘HessianPHP/HessianService.php’;//加载核心文件
class TestService
{
public function __construct()
{

}   

public function add($numa, $numb)   
{   
    return $numa + $numb;   
}   

public function check()   
{   
    return '[email protected]';   
}   

}
$test = new TestService();
$hessian = new HessianService( $test, array(‘displayInfo’ => true) );
$hessian->handle();//注意这里不是网上的$hessian->service(),可能是版本不一样,改了吧!我也是看了源码才知道!
?> [/code]client 端:<?php include_once 'HessianPHP/HessianClient.php'; $url = "http://localhost/phpservice/hessianserver/server.php"; $options = new HessianOptions(); $client = new HessianClient( $url, $options ); $num = $client->add( 3, 5 ); echo $num;//得到:8; echo $client->check();//得到:[email protected]