แนะนำ ลองใช้ ตัวนี้
https://github.com/skolodyazhnyy/symfony-rpc-bundle
ตัวอย่างฝั่ง Server
โค้ด: เลือกทั้งหมด
namespace Sample\WebserviceBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Seven\RpcBundle\XmlRpc\Server;
class CalcHandler {
public function add($a, $b) { return $a + $b; }
public function sub($a, $b) { return $a - $b; }
public function div($a, $b) { return $a / $b; }
}
class WebServiceController extends Controller
{
public function handleAction()
{
// Create XML-RPC Server
$server = new Server();
// Add handlers
$server->addHandler('help', function() { return "Use methods calc.add, calc.sub and calc.div."; });
$server->addHandler('calc', 'CalcHandler');
// Handler request and return response
return $server->handle($this->getRequest());
}
}
โค้ด: เลือกทั้งหมด
$client = new Seven\RpcBundle\XmlRpc\Client("http://xmlrpcservice/endpoint");
echo $client->call('calc.add', array(1, 2)); // echo 3
echo $client->call('calc.sub', array(2, 3)); // echo -1