doushen8391 2010-12-21 21:51
浏览 38
已采纳

Zend XMLRPC服务执行/调用类

I have a Class the runs a process by itself

Pseudo 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."
";
  }
  // This is the change for the XMLRPC
  /*
  public function startProcess($value) {
    // run process here
    echo "Process Started: ".$value."
";
  }
  */

  /**
   * 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
}

To execute the class I would do something like this

include('MyClass.php');

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

Now I want this to be initialized by a XMLRPC call where I would just pass it a variable in the method call. I was following this tutorial but I'm not sure if I can, here is what I'm trying. Now instead of setting X before hand I'm just going to pass it to the startProcess function

XMLRPC Server:

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 Client:

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

Here is the response I get:

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
        )

)

Why doesn't this work? Just trying to find a way for XMLRPC to kick off my class process, suggestions?

  • 写回答

1条回答 默认 最新

  • doufu2396 2010-12-22 16:36
    关注

    Ok so after much debugging my code I found that my docblock declaration was incorrect.

    For each public function in the class you need to have a docblock that defines the parameters and return data type(s).

    Example of what I had:

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

    Example of what it should be:

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

    Hope this helps someone

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭