2009年1月22日星期四

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

-- Benjamin Eberlei <kontakt@beberlei.de> wrote
(on Thursday, 22 January 2009, 11:56 AM +0100):
> It is possible, but i wouldnt say recommended!
>
> I wouldnt publish a webservice inside an action controller. The overhead is
> considerable and they don't really match together, the front controller,
> routing and execution of the action seems quite overhead for "finding" a
> service that dispatches to subfunctions and methods, never uses any
> fucntions from the Request and Response objects and disables the View
> Renderer.

I have to concur with this assessment as well. While I've certainly
implemented XML-RPC and SOAP servers within MVC actions, the fact of the
matter is that there really is a mismatch, and you have a ton of
overhead that goes relatively unused. It's much better to create
endpoints and use mod_rewrite to map them to "pretty URLs".

Once Zend_Application is out the door, it also becomes trivial for your
services to share much of the same environment as your MVC layer --
meaning you won't have to worry about code duplication, either.

As for Ben's discussion of ACL and authentication, these can be
incorporated in your service and request layers, respectively. I've
built services that require you get an authentication token, and pass it
as the last variable of each request; the request object then checks for
this token, and returns an error if missing. ACLs can be incorporated
into your service layer at that point.

> I have written a blog post on that:
>
> http://www.whitewashing.de/blog/articles/106
>
> When you are using the current .htaccess mod_rewrite out the controller
> documentation, you can do as follows:
>
> 1. new file webservice/myservice/index.php in your projects document root.
> 2. publish webservice there
> 3. any request to webservice/myservice/ will be recognized to have a file
> present and use the new file you generated.
> 4. if you need authentication build a proxy around your webservice that
> includes the ACL and Auth (with HTTP Authentication) from your normal
> application.
>
> For this to work your bootstrapping mechanism needs to be sufficiently
> configurable.
>
> This is the way i would always build a webservice with ZF.
>
> On Thu, 22 Jan 2009 02:40:06 -0800 (PST), anz_nabble <anz@feathersoft.de>
> wrote:
> >
> > Is it possible to implement the Xml rpc server just like an action inside
> > a
> > Cotroller ?
> >
> > I mean, just like...
> >
> >
> > function runXmlRpcAction()
> > {
> > 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
> >
> >
> >
> > }
> >
> >
> > Can anyone provide me the procedure to make a simple webservice using
> > XMLRPC
> > ?
> > --
> > View this message in context:
> >
> http://www.nabble.com/Is-it-possible-to-write-the-Xmlrpc-server-code-as-an-action-inside-a-cotroller--tp21601672p21601672.html
> > Sent from the Zend Web Services mailing list archive at Nabble.com.
>

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: