你好,我正在尝试使用hessian创建一个web服务,但我似乎没有任何运气在实现即使是最基本的例子。
This is my client
<?php
include_once './Hessian/HessianClient.php';
$testurl = 'http://localhost/HessianPHP/server.php';
$proxy = new HessianClient($testurl);
echo $proxy->div(2,5);
?>
这是我的服务器代码:
<?php
include_once 'Hessian/HessianService.php';
$service = new HessianService(new Math());
$service->handle();
?>
class Math {
function add($n1,$n2) {
return $n1+$n2;
}
function sub($n1,$n2) {
return $n1-$n2;
}
function mul($n1,$n2) {
return $n1*$n2;
}
function div($n1,$n2) {
return $n1/$n2;
}
}
当我运行这段代码时,我得到这个错误:
致命错误:未捕获异常'HessianFault'与消息'Code not recognized as top element'在E:'Program Files'xampp'htdocs'HessianPHP' Hessian2'Hessian2ServiceParser.php:38堆栈跟踪:#0 E:'Program Files'xampp'htdocs'HessianPHP' hessianlient .php(74): Hessian2ServiceParser->parseTop() #1 E:'Program Files'xampp' HessianPHP' hessianlient .php(111): HessianClient->_hessianCall('div', Array) #2 E:'Program Files'xampp'htdocs'HessianPHP' hessianlient .php('div', Array):HessianClient->_call('div', Array) #3 E:'Program Files'xampp'htdocs'HessianPHP'client.php(5): HessianClient->div(2,5) #4 {main}抛出在E:'Program Files'xampp'htdocs'HessianPHP'Hessian'Hessian2'Hessian2ServiceParser.php第38行
我在这里做错了什么?
index . php(客户端)
<?php
require_once 'HessianPHP/src/HessianClient.php';
$testurl = 'http://path/to/mathservice.php' ;
$proxy = &new HessianClient($testurl);
try{
echo '<pre>';
print_r($proxy->add(1 , 3));
echo '</pre>';
} catch (Exception $ex){
echo 'Exception: ' . $ex->getMessage();
}
server (mathservice.php)
<?php
include_once 'HessianPHP/src/HessianService.php';
include_once 'Math.php';
$service = new HessianService(new Math());
$service->handle();
Math.php
<?php
class Math{
function add($n1,$n2) {
return $n1+$n2;
}
function sub($n1,$n2) {
return $n1-$n2;
}
function mul($n1,$n2) {
return $n1*$n2;
}
function div($n1,$n2) {
return $n1/$n2;
}
}
希望有帮助。我认为有一些语法错误在你的代码(你写数学类没有php标签的方式是奇怪的)。如果你得到黑屏,检查你的日志文件(error.log)。