phpsymfonyzend-frameworkxml-rpczend-xmlrpc

How to configure XML-RPC server in Symfony


In my website I need to configure the REST, XML-RPC, SOAP servers.

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

How to configure the Zend XmlRpc server in Symfony?

Any useful links with step by step configuration?

Or any other XML-RPC which can be used with symfony

Thanks in advance, SVN


Solution

  • I have used zend xmlrpc with symfony

    composer.json

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

    config.yml

    services:
       MyTestService:
            class: Acme\DemoBundle\Controller\MyTestService
            arguments: ["@doctrine.orm.entity_manager"] 
    

    routing.yml

    _xmlrpc:
        pattern:  /xmlrpc
        defaults: { _controller: AcmeDemoBundle:Xmlrpc:index }
    _xmlrpc_test:
        pattern:  /xmlrpc/test
        defaults: { _controller: AcmeDemoBundle:Xmlrpc:test }
    

    controller

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

    MyTestService

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