Zend XMLRPC服务执行/调用类

时间:2010-12-21 21:51:34

标签: php web-services class zend-framework xml-rpc

我有一个Class,它自己运行一个进程

伪类

class MyClass {
  private $x;
  private $y

  // filename is INI file, each project have its own INI file
  public function __construct($filename) {
    // read and set value from INI file
    // set some default values here as well
  }

  /**
   * Start Process
   *
   * @param 
   * @return
   */
  public function startProcess() {
    // run process here
    $y = $this->getX(); // and so on
    echo "Process Started: ".$y."\n";
  }
  // This is the change for the XMLRPC
  /*
  public function startProcess($value) {
    // run process here
    echo "Process Started: ".$value."\n";
  }
  */

  /**
   * Set X
   *
   * @param $x
   * @return
   */
  private function setX($x) {
    $this->x = $x;
  }

  /**
   * Get X
   *
   * @param 
   * @return $x
   */
  private function getX() {
    return $this->x;
  }

  // and so on
}

要执行课程,我会做类似的事情

include('MyClass.php');

$process = new MyClass('file.ini');
$process->setX('blah');
$process->startProcess();

现在我想通过XMLRPC调用初始化它,我只是在方法调用中传递一个变量。我跟着这个tutorial,但我不确定我能否,这就是我正在尝试的。现在不是手动设置X而是将其传递给startProcess函数

XMLRPC服务器:

ini_set("include_path", "/usr/share/php/libzend-framework-php");
require_once('Zend/XmlRpc/Server.php');

/**
 * Start Process Wrapper
 * 
 * @param 
 * @return 
 */
function startProcessWrapper($value) {
    include('MyClass.php'); // I have change the startProcess() to take a variable

    $process = new MyClass('file.ini');
    $process->startProcess('passing x here');
}

$server = new Zend_XmlRpc_Server();
$server->addFunction('startProcessWrapper', 'webservice');
echo $server->handle();

XMLRPC客户端:

ini_set("include_path", "/usr/share/php/libzend-framework-php");
require_once('Zend/XmlRpc/Client.php');

$server = new Zend_XmlRpc_Client('http://localhost/xmlrpc_server.php');
$client = $server->getProxy(); 

$request = array(
  array(
    'methodName' => 'system.listMethods', 
    'params'     => array() 
  ), 
  array( 
    'methodName' => 'system.methodHelp', 
    'params'     => array('webservice.startProcess') 
  ),  
  array( 
    'methodName' => 'webservice.startProcess', 
    'params'     => array('123456') 
  ));

  $response = $client->system->multicall($request); 
  echo print_r($response,true);

以下是我得到的回复:

Array
(
    [0] => Array
        (
            [0] => system.listMethods
            [1] => system.methodHelp
            [2] => system.methodSignature
            [3] => system.multicall
            [4] => webservice.startProcess
        )

    [1] => Start Process Wrapper
    [2] => Array
        (
            [faultCode] => 623
            [faultString] => Calling parameters do not match signature
        )

)

为什么这不起作用?只是试图找到一种方法让XMLRPC启动我的课程流程,建议?

1 个答案:

答案 0 :(得分:2)

好的,经过多次调试我的代码后,我发现我的docblock声明不正确。

对于类中的每个公共函数,您需要有一个定义参数和返回数据类型的docblock。

我的例子:

  /**
   * Set X
   *
   * @param $x
   * @return
   */
  public function setX($x) {
    $this->x = $x;
  }

应该是什么的例子:

  /**
   * Set X, you can give more description here for help functionality
   *
   * @param string
   * @return
   */
  public function setX($x) {
    $this->x = $x;
  }

希望这有助于某人