0

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?

aleczandru
  • 5,319
  • 15
  • 62
  • 112
  • Does the error come from the client or the server? Is this example from the Hessian website, or are there working examples there you can try? If you've got the example from somewhere, it is helpful to offer the URL of that, so people who have a couple of minutes may use that source to see if you might have missed something. – halfer Jun 11 '13 at 20:26

1 Answers1

1

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

anasanjaria
  • 1,308
  • 1
  • 15
  • 19