Powered by PmWiki
First we create a proxy that points to the url of the published Java based service.
include_once( 'HessianClient.php' ); $testurl = 'http://localhost:8080/hessian/service/userService'; $proxy = &new HessianClient($testurl);
Now we need to perform remote calls to a method named findUser() with a string argument, this method returns a User object:
Ok, but wait, when we execute the script we get the following if error level is at HESSIAN_TRIGGER_ERROR: (This only applies to PHP 4)
array ( 'code' => 'NoSuchMethodException' )
So what happened? Because of PHP 4 internals, dynamically called methods are lowercased at runtime so you are really calling "finduser" and not "findUser".
But there's a way out. Before calling the method, you have to declare the remote method's name so HessianPHP can resolve it's name before sending the call, like this:
This way you can execute the call with no problem. This behavior is documented in the FAQ and note that PHP 5 is not affected.
NOTE: These function use to be in the proxy object itself but it was moved into a general configuration class named just Hessian, this to leave the clean proxy object completely.
Now we execute the call and print_r() the results for debugging:
include_once( 'HessianClient.php' ); $testurl = 'http://localhost:8080/hessian/service/userService' ; $proxy = &new HessianClient($testurl); Hessian::remoteMethod($testurl,'findUser'); $user = $proxy->findUser('mgomez'); print_r($user);
We get the following:
Array ( [name] => Manolo [lastName] => Gómez [code] => 123 )
HessianPHP returns an associative array where indexes are the object field names. If want to get an object of the right class, you have to declare a class and if the type is known you have to map the fully qualified name of the remote class to a local type using the mapRemoteType() function, like this:
Note that lastName field contains the accentuated character ó. Hessian spec states that strings are utf-8 encoded so the protocol can handle special characters seamlessly.