-- 张心灵 <[EMAIL PROTECTED]> wrote
(on Sunday, 17 June 2007, 02:04 PM +0800):
> Month ago, I tried Zend_XmlRpc lib,but the result is pool!
> Now ZF 1.0RC2 was released,I tried agin,but the result is even worse!
> The Server code is:
>
> <?php
> require './Zend/Loader.php';
>
> Zend_Loader::loadClass('Zend_XmlRpc_Server');
>
> class Hash_Server
> {
> public function algos()
> {
> return hash_algos();
> }
> public function hash($data, $algo = 'md5')
> {
> if(!in_array($algo, $this->algos)) throw new Exception(' ֧ ֵ hash ');
> return hash($algo, $data);
> }
> }
You need to use docblocks for each public method detailing the argument
and return types:
class Hash_Server
{
/**
* Return list of supported hash algorithms
*
* @return string
public function algos()
{
return hash_algos();
}
/**
* Hash a string according to an algorithm
*
* @param string $data
* @param string $algo Defaults to 'md5'
* @return string
*/
public function hash($data, $algo = 'md5')
{
if(!in_array($algo, $this->algos)) throw new Exception(' ֧ ֵ hash
');
return hash($algo, $data);
}
}
Internally, the XmlRpc server (and any server using
Zend_Server_Reflection) utilizes the docblocks to determine the
parameter and return value types; without these, it will throw
exceptions as it cannot securely compare the incoming request against
the method signatures.
> $server = new Zend_XmlRpc_Server;
> $server->setClass('Hash_Server','hash');
>
> $server->handle()
The above line should be:
echo $server->handle();
Otherwise no response is returned.
> And the client is like this:
>
> <?php
> require './Zend/Loader.php';
>
> Zend_Loader::loadClass('Zend_XmlRpc_Client');
>
> $client = new Zend_XmlRpc_Client('http://localhost/zf/server.php');
>
> echo '<br/>';
> print_r($client->hash->algos());
The above won't work. You need to use the proxy to make that work:
$proxy = $client->getProxy();
print_r($proxy->hash->algos());
This is documented in the manual:
http://framework.zend.com/manual/en/zend.xmlrpc.client.html#zend.xmlrpc.client.requests-and-responses
> echo '</br>';
> echo $client->hash->hash('12345','md5');
Same thing with the above --> $proxy->hash->hash('12345', 'md5');
> The result is like this:
>
> Fatal error: Uncaught exception 'Zend_XmlRpc_Client_FaultException' with
> message 'Failed to parse response' in E:\Program Files\web\zf\Zend\XmlRpc\
As for the above is because no response was returned. See my above
comments.
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/