我在 symfony 中使用了 zend xmlrpc
作曲家.json
"zendframework/zend-xmlrpc": "2.1.*"
配置.yml
services:
MyTestService:
class: Acme\DemoBundle\Controller\MyTestService
arguments: ["@doctrine.orm.entity_manager"]
路由.yml
_xmlrpc:
pattern: /xmlrpc
defaults: { _controller: AcmeDemoBundle:Xmlrpc:index }
_xmlrpc_test:
pattern: /xmlrpc/test
defaults: { _controller: AcmeDemoBundle:Xmlrpc:test }
控制器
public function indexAction()
{
$server = new \Zend\XmlRpc\Server;
$server->setClass($this->get('MyTestService'));
$response = new Response();
$response->headers->set('Content-Type', 'text/xml; charset=ISO-8859-1');
ob_start();
$server->handle();
$response->setContent(ob_get_clean());
return $response;
}
public function testAction()
{
$client = new \Zend\XmlRpc\Client('`http://127.0.0.1/symfony_xmlrpc/web/app_dev.php/xmlrpc`');
$result= $client->call('ping', array('test'));
echo '<br/><br/>XmlRpc:<br/>';
var_dump ( $result );
$response = new Response();
$response->headers->set('Content-Type', 'text');
ob_start();
$response->setContent('testme');
return $response;
}
我的测试服务
namespace Acme\DemoBundle\Controller;
class MyTestService {
/**
* A simple ping service
*
* @param string $value
* @return string
*/
function ping($value) {
return $value . ' back from server symfony';
}
/**
* A simple pong service
*
* @param string $token
* @param array $arg
* @return array
*/
function pong($token, $arg) {
return array($token.'data'=>$arg);
}
}