2009年1月22日星期四

Re: [fw-webservices] Is it possible to write the Xmlrpc server code as an action inside a cotroller?

I had tried to implement a simple webservice, but it didn't give the result.
I had created the environment in such a way that,


First I created a folder caller xmlrpc in my Aplication - root folder

inside that I placed a .htaccess file and index.php file

In the .htaccess file( placed in localhost/myapplication/xmlrpc/ ) I put
RewriteEngine off


In the index.php file ie; ( localhost/myapplication/xmlrpc/ )
<?php
include '../application/bootstrap.php';
$bootstrap = new Bootstrap('general');
$bootstrap->runXmlRpc(); // Running runxmlRpc function


The bootstrap.php is located in localhost/myapplication/application/

Inside the bootstrap file I wrote a class called Bootstrap

ie;


<?php

class Bootstrap
{
public function __construct($deploymentEnvironment)
{



}

public function runXmlRpc()
{
Zend_Loader::loadClass('Zend_XmlRpc_Server');


$server = new Zend_XmlRpc_Server(); // Initializes XMLRPC server

require_once 'Listnews.php'; // Includes class files that attach to
server

$server->setClass('Listnews', 'news'); // Attaches class methods as
XML-RPC method handlers

$response = $server->handle(); // Handle RPCs

$response->setEncoding('UTF-8'); // Sets response character encoding

header( 'Content-Type: text/xml; charset=UTF-8' ); // Sets HTTP header

echo $response; // Outputs the response

}


}


Here I attached a class named Listnews

Inside the Listnews class I wrote the function

public function changeStatus()
{

$sql = "UPDATE xmlrpc_news SET `status`='N' WHERE news_id=5";
mysql_query($sql);

return true;
}


This function is for updating a field of a database record.

This is what I have done to implement the server part.

Then I created the client part inside a controller(obviously inside an
Action) .

and it is just like

$client = new Zend_XmlRpc_Client('http://192.168.0.122/webservice/xmlrpc/');


$result = $client->call('news.selectNews');


When run the client I got Eror Message as follows

Uncaught exception 'Zend_XmlRpc_Client_FaultException' with message 'Failed
to parse response' in
D:\xampp\htdocs\webservice\library\Zend\XmlRpc\Client.php:348 Stack trace:
#0
D:\xampp\htdocs\webservice\application\controllers\WebclientController.php(18):
Zend_XmlRpc_Client->call('news.changeStatus') #1
D:\xampp\htdocs\webservice\library\Zend\Controller\Action.php(503):
WebclientController->indexAction() #2
D:\xampp\htdocs\webservice\library\Zend\Controller\Dispatcher\Standard.php(285):
Zend_Controller_Action->dispatch('indexAction') #3
D:\xampp\htdocs\webservice\library\Zend\Controller\Front.php(934):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http)) #4
D:\xampp\htdocs\webservice\index.php(48): Zend_Controller_Front->dispatch()
#5 {main} thrown in
D:\xampp\htdocs\webservice\library\Zend\XmlRpc\Client.php on line 348

Will anyone please help me to find out my mistakes. I am a newbie in Zend
Framework


--
View this message in context: http://www.nabble.com/Is-it-possible-to-write-the-Xmlrpc-server-code-as-an-action-inside-a-cotroller--tp21601672p21602313.html
Sent from the Zend Web Services mailing list archive at Nabble.com.

没有评论: