(on Sunday, 19 October 2008, 02:24 PM -0700):
> Hello,
>
> I am using Zend 1.6 with Dojo 1.2. I tried to set up a JSON-RPC server
> with Zend_JSON_Server and got the following error message from Firebug:
>
> SyntaxError: missing ) in parenthetical message=missing ) in
> parenthetical
>
> SMD content (from http://localhost/TestSite/rpc/smd):
>
> {"SMDVersion":".1","serviceType":"JSON-RPC","methods":
> [{"name":"add","serviceURL":"\/TestSite\/rpc\/service","parameters":
> [{"name":"x","type":"integer"},{"name":"y","type":"integer"}]},
> {"name":"subtract","serviceURL":"\/TestSite\/rpc\/
> service","parameters":[{"name":"x","type":"integer"},
> {"name":"y","type":"integer"}]},{"name":"multiply","serviceURL":"\/
> TestSite\/rpc\/service","parameters":[{"name":"x","type":"integer"},
> {"name":"y","type":"integer"}]},{"name":"divide","serviceURL":"\/
> TestSite\/rpc\/service","parameters":[{"name":"x","type":"integer"},
> {"name":"y","type":"integer"}]},{"name":"echomsg","serviceURL":"\/
> TestSite\/rpc\/service"}]}{"error":{"code":-32600,"message":"Invalid
> Request","data":null},"id":null}
>
> If I insert a comma (,) between } and {"error" manually, I will not get
> this error message. Is this a bug or I did something wrong here?
Looks like you requested the SMD via the JSON-RPC server *AND* then also
dispatched the request -- which results in TWO JSON results. If you're
requesting just the SMD, make sure you exit after returning it, and
don't attempt to process the request as a JSON-RPC request..
> Controller:
>
> Class RpcController extends CustomControllerAction{
> public function smdAction() {
> $this->_helper->layout->disableLayout();
>
> /* 1. Instantiate the server object */
> $server = new Zend_Json_Server();
>
> /* 2. Attach class to the server object */
> $server->setClass('Calculator');
> $server->setClass('test');
>
> if ('GET' == $_SERVER['REQUEST_METHOD']) {
> $server->setTarget($this->getHelper('url')-
> >url(array('controller'=>'rpc', 'action'=>'service')))
> ->setId($this->getHelper('url')->url(array('controller'=>'rpc',
> 'action'=>'service')))
> ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
>
> $smd = $server->getServiceMap();
>
> // Set Dojo compatibility:
> $smd->setDojoCompatible(true);
> header('Content-Type: application/json');
> echo $smd;
> }
> /* 3. Handle the request */
> $server->handle();
> }
>
> public function serviceAction() {
> $this->_helper->layout->disableLayout();
> $server = new Zend_Json_Server();
> $server->setClass('Calculator');
> $server->setClass('test');
> $server->setAutoEmitResponse(true);
> $server->handle();
> }
> ......
> }
>
> view:
>
> <script type="text/javascript">
> dojo.require("dojo.rpc.JsonService");
> var server = new dojo.rpc.JsonService("/TestSite/rpc/smd")
> console.debug(server);
> var t = server.echomsg();
> console.debug(t);
> t.addCallback( function(msg) {
> alert(msg);
> });
>
> </script>
>
> Feedbacks are welcomed.
>
> Bin
>
>
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论