Warning: strftime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/hessianphp/htdocs/pmwiki.php on line 242

Warning: Cannot modify header information - headers already sent by (output started at /home/project-web/hessianphp/htdocs/pmwiki.php:242) in /home/project-web/hessianphp/htdocs/pmwiki.php on line 727
HessianPHP | Main / Quick Start Guide

From HessianPHP

Main: Quick Start Guide

Consuming a Hessian web service

To start consuming remote Hessian web services all you need to do is:

  1. Include or require the file HessianClient.php
  2. Create a HessianClient object passing the url of the service
  3. Call methods

This is an example code that creates a proxy to a remote service, calls several methods and prints the results:

include_once 'HessianClient.php';
$testurl = 'http://localhost:8080/resin-doc/protocols/tutorial/hessian-add/hessian/math';
$proxy = &new HessianClient($testurl);
echo $proxy->add(2,5); 
echo $proxy->sub(2,5);
echo $proxy->mul(2,5);
echo $proxy->div(2,5); 

After a call you can check the value of the Hessian::error() function:

if(Hessian::error()) {
    // do something with the error
}

And for PHP5 you might want to enclose the code inside a try..catch block, like this:

try {
    echo $proxy->add(2,5); 
} catch (Exception $e) {
    // do something with the exception
}

Publishing a Hessian web service

You have to create a script in the web server following this steps:

  1. Include or require the file HessianService.php.
  2. Create a HessianService wrapper object
  3. Register a previously created or new object by calling registerObject().
  4. Execute the service() method.

Thus, for example, if we want to publish a calculator service that is compatible with the previous example, we have to create a class something like this:

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

Then create the service wrapper and register a Math object to publish it:

include_once 'HessianService.php';
$wrapper = &new HessianService();
$wrapper->registerObject(new Math);
$wrapper->service();

That's it. Now we have successfully published a Hessian web service from a common PHP object. The url of the service is the same url of the script.

If you try to access the url using a web browser, you will get a 500 error because Hessian requires POST to operate.


Warning: strftime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/hessianphp/htdocs/pmwiki.php(461) : regexp code on line 1
Retrieved from http://hessianphp.sourceforge.net/index.php?n=Main.QuickStart
Page last modified on December 21, 2005, at 03:46 AM

Warning: fopen(wiki.d/.flock): failed to open stream: Permission denied in /home/project-web/hessianphp/htdocs/pmwiki.php on line 355

PmWiki can't process your request

Cannot acquire lockfile

We are sorry for any inconvenience.