doutan2111 2013-06-11 18:36
浏览 22

实现Hessian Web服务

Hi I am trying to create a web service using hessian but I can't seem to have any luck in implementing even the most basic example.

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); 

?>

And this is my server code:

<?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;    
  }
}

When I run this code I get this error:

Fatal error: Uncaught exception 'HessianFault' with message 'Code not recognized as a top element' in E:\Program Files\xampp\htdocs\HessianPHP\Hessian\Hessian2\Hessian2ServiceParser.php:38 Stack trace: #0 E:\Program Files\xampp\htdocs\HessianPHP\Hessian\HessianClient.php(74): Hessian2ServiceParser->parseTop() #1 E:\Program Files\xampp\htdocs\HessianPHP\Hessian\HessianClient.php(111): HessianClient->_hessianCall('div', Array) #2 E:\Program Files\xampp\htdocs\HessianPHP\client.php(5): HessianClient->_call('div', Array) #3 E:\Program Files\xampp\htdocs\HessianPHP\client.php(5): HessianClient->div(2, 5) #4 {main} thrown in E:\Program Files\xampp\htdocs\HessianPHP\Hessian\Hessian2\Hessian2ServiceParser.php on line 38

What am I doing wrong here?

  • 写回答

1条回答 默认 最新

  • dongxiao3694 2014-04-15 06:31
    关注

    index.php ( client )

    <?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;
        }
    }
    

    Hope it helps. I think there is some syntax error in your code ( the way you write Math class without php tags is weird ). If u r getting blank screen then check your log file ( error.log ) .

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能