Php 如何在Symfony中配置XML-RPC服务器

Php 如何在Symfony中配置XML-RPC服务器,php,symfony,zend-framework,xml-rpc,zend-xmlrpc,Php,Symfony,Zend Framework,Xml Rpc,Zend Xmlrpc,在我的网站中,我需要配置其余的XML-RPC和SOAP服务器 REST: I have used the FriendsOfSymfony REST bundle SOAP: PHP SOAP used (doc from symfony website XML-RPC: I have planed to use the Zend XmlRpc 如何在Symfony中配置Zend XmlRpc服务器? 是否有任何有用的带有逐步配置的链接 或可与symfony一起使用的任何其他XML-RPC 提

在我的网站中,我需要配置其余的XML-RPC和SOAP服务器

REST: I have used the FriendsOfSymfony REST bundle
SOAP: PHP SOAP used (doc from symfony website
XML-RPC: I have planed to use the Zend XmlRpc
如何在Symfony中配置Zend XmlRpc服务器?

是否有任何有用的带有逐步配置的链接

或可与symfony一起使用的任何其他XML-RPC

提前感谢,,
SVN

我已将zend xmlrpc与symfony一起使用

composer.json

"zendframework/zend-xmlrpc": "2.1.*"
config.yml

services:
   MyTestService:
        class: Acme\DemoBundle\Controller\MyTestService
        arguments: ["@doctrine.orm.entity_manager"] 
_xmlrpc:
    pattern:  /xmlrpc
    defaults: { _controller: AcmeDemoBundle:Xmlrpc:index }
_xmlrpc_test:
    pattern:  /xmlrpc/test
    defaults: { _controller: AcmeDemoBundle:Xmlrpc:test }
routing.yml

services:
   MyTestService:
        class: Acme\DemoBundle\Controller\MyTestService
        arguments: ["@doctrine.orm.entity_manager"] 
_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;

}
Xmlrpc(请求发送到外部url以检索数据)通过使用simple
sudo apt get install php5 Xmlrpc
,我们可以安装
Xmlrpc
。我们可以在symfony和php中使用它,也可以根据我们需要的url格式使用它。在控制器中:

public function testAction()
{

    $method = 'index.bus';
    $date = '2002-02-20';
    $source = 112;
    $dest = 69;
    $s_id = 1310;
    $seat = 'seat';
    $request = xmlrpc_encode_request($method, array("date"=>$date,
        "sourceids"=>$source,
        "destinationids"=>$dest,
        "serviceids"=>$s_id,
        "selected_seat"=>$seat));

    $context = stream_context_create(array('http' => array(
      'method' => "POST",
      'header' => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\n",
      'content' => $request
    )));

    //(external url) their format of request
    $file = file_get_contents("http://url.com/api/cabs/server.php? SecurityKey=ATSELKSWER", false, $context);
   $response = xmlrpc_decode($file);

    if ($response && xmlrpc_is_fault($response)) {
      trigger_error("xmlrpc:$response[faultString]($response[faultCode])");
    } 
    else{
        print_r($response);
    }
}