Recent Changes - Search:

Documents

Community

Related Projects

Powered by PmWiki

Quick Start Guide

Main.QuickStart History

Hide minor edits - Show changes to markup

December 21, 2005, at 03:46 AM by 127.0.0.1 -
Changed lines 30-31 from:
    echo $proxy->add(2,5); } catch (Exception $e) {
to:
    echo $proxy->add(2,5); 

} catch (Exception $e) {

December 21, 2005, at 03:28 AM by 127.0.0.1 -
Added lines 1-69:

(:title 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.

Edit - History - Print - Recent Changes - Search
Page last modified on December 21, 2005, at 03:46 AM

PmWiki can't process your request

Cannot acquire lockfile

We are sorry for any inconvenience.