Case solved.
I used invalid URL, that why request handler didn't recognize the
service call.
Following is the code that works:
rpc.py:
-------------------
from gluon.tools import Service
service = Service(globals())
def call():
session.forget()
return service()
@service.amfrpc3("mydomain")
def test():
return "Test!!!"
Flex
-------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import mx.messaging.channels.NetConnectionChannel;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.messaging.channels.AMFChannel;
private function resultHandler(event:ResultEvent):void
{
trace(event.result.toString());
}
private function faultHandler(event:FaultEvent):void
{
trace(event.fault.message);
}
private function fire():void
{
amfService3.test();
}
]]>
</mx:Script>
<mx:RemoteObject
id="amfService3"
endpoint="http://127.0.0.1:8000/AppTryout/rpc/call/amfrpc3"
destination="mydomain"
showBusyCursor="true">
<mx:method name="test" result="resultHandler(event)"
fault="faultHandler(event)"/>
</mx:RemoteObject>
<mx:Button x="250" y="150" label="Fire" click="fire();"/>
</mx:Application>
--------------
Massimo, thanks for your answers and sorry for trouble!
On Mar 10, 12:29 am, Igor Gassko <[email protected]> wrote:
> I've debugged Flex for a while and found out that
> "Service.ResourceNotFound" comes over from the server.
> Since I don't have a clue how to debug web2py, I just dig in pyamf
> sources untill I found out that Service.ResourceNotFound is a string
> message of UnknownServiceError which is raised in
> \pyamf\remoting\gateway\__init__.py at line 395 in 'def
> getServiceRequest'.
> I can't understandf much from the code of that function, because I'm
> not too savvy with Python syntax or pyamf classes but I'm qute sure
> that the problem is there. Or at least, this is where the request gets
> rejected.
> Is there any way to debug this stuff directly? SOS!
>
> On Mar 9, 9:04 pm, iggass <[email protected]> wrote:
>
>
>
> > Hello!
>
> > I'm trying to deploy basic connectivity between Flex AS3 application
> > and web2py server-side. In order to achieve this noble cause I studied
> > the official tutorial (http://www.web2py.com/AlterEgo/default/show/22)
> > and the official documentation (http://web2py.com/book/default/section/
> > 9/2).
> > So, I created two controllers 'rpc' and 'rpc2' as follows:
>
> > rpc.py
> > ---------------
> > from gluon.tools import Service
> > service = Service(globals())
>
> > def call():
> > session.forget()
> > return service()
>
> > @service.amfrpc
> > def test():
> > return "Test!!!"
>
> > rpc2.py
> > ---------------
> > import pyamf
> > import pyamf.remoting.gateway
>
> > def test():
> > return "Test!!!"
>
> > services={'test.test':test}
>
> > def gateway():
> > base_gateway = pyamf.remoting.gateway.BaseGateway(services)
> > context = pyamf.get_context(pyamf.AMF0)
> > pyamf_request = pyamf.remoting.decode(request.body.read(),
> > context)
> > pyamf_response = pyamf.remoting.Envelope(pyamf_request.amfVersion,
> > pyamf_request.clientType)
> > for name, message in pyamf_request:
> > pyamf_response[name] = base_gateway.getProcessor(message)
> > (message)
> > response.headers['Content-Type'] = pyamf.remoting.CONTENT_TYPE
> > return pyamf.remoting.encode(pyamf_response, context).getvalue()
>
> > -------------
>
> > After that, I tried accessing exposed amf services using both
> > controllers respectively via browser through the following URLs:
>
> >http://127.0.0.1:8000/AppTryout/rpc/call/amfrpc/testhttp://127.0.0.1:...
>
> > In both cases I recieve similar errors:
>
> > forhttp://127.0.0.1:8000/AppTryout/rpc/call/amfrpc/test:
> > ---------------------------------------------------------------------------
> > ------
> > Traceback (most recent call last):
> > File "gluon/restricted.py", line 173, in restricted
> > File "//server2003/web2py/applications/AppTryout/controllers/
> > rpc.py", line 13, in <module>
> > File "gluon/globals.py", line 96, in <lambda>
> > File "//server2003/web2py/applications/AppTryout/controllers/
> > rpc.py", line 7, in call
> > File "gluon/tools.py", line 2942, in __call__
> > File "gluon/tools.py", line 2885, in serve_amfrpc
> > File "\\server2003\web2py\library.zip\pyamf\remoting\__init__.py",
> > line 634, in decode
> > File "\\server2003\web2py\library.zip\pyamf\util\__init__.py", line
> > 322, in read_uchar
> > File "\\server2003\web2py\library.zip\pyamf\util\__init__.py", line
> > 298, in _read
> > File "\\server2003\web2py\library.zip\pyamf\util\__init__.py", line
> > 646, in read
> > IOError: Attempted to read 1 bytes from the buffer but only 0 remain
>
> > In file: \\server2003\web2py\applications\AppTryout/controllers/rpc.py
> > from gluon.tools import Service
> > service = Service(globals())
>
> > def call():
> > session.forget()
> > return service()
>
> > @service.amfrpc
> > def test():
> > return "Test!!!"
>
> > response._vars=response._caller(call)
>
> > forhttp://127.0.0.1:8000/AppTryout/rpc/call/amfrpc/test:
> > ---------------------------------------------------------------------------
> > ------
> > Traceback (most recent call last):
> > File "gluon/restricted.py", line 173, in restricted
> > File "//server2003/web2py/applications/AppTryout/controllers/
> > rpc2.py", line 18, in <module>
> > File "gluon/globals.py", line 96, in <lambda>
> > File "//server2003/web2py/applications/AppTryout/controllers/
> > rpc2.py", line 12, in gateway
> > File "\\server2003\web2py\library.zip\pyamf\remoting\__init__.py",
> > line 634, in decode
> > File "\\server2003\web2py\library.zip\pyamf\util\__init__.py", line
> > 322, in read_uchar
> > File "\\server2003\web2py\library.zip\pyamf\util\__init__.py", line
> > 298, in _read
> > File "\\server2003\web2py\library.zip\pyamf\util\__init__.py", line
> > 646, in read
> > IOError: Attempted to read 1 bytes from the buffer but only 0 remain
>
> > In file: \\server2003\web2py\applications\AppTryout/controllers/
> > rpc2.py
> > import pyamf
> > import pyamf.remoting.gateway
>
> > def test():
> > return "Test!!!"
>
> > services={'test.test':test}
>
> > def gateway():
> > base_gateway = pyamf.remoting.gateway.BaseGateway(services)
> > context = pyamf.get_context(pyamf.AMF0)
> > pyamf_request = pyamf.remoting.decode(request.body.read(),
> > context)
> > pyamf_response = pyamf.remoting.Envelope(pyamf_request.amfVersion,
> > pyamf_request.clientType)
> > for name, message in pyamf_request:
> > pyamf_response[name] = base_gateway.getProcessor(message)
> > (message)
> > response.headers['Content-Type'] = pyamf.remoting.CONTENT_TYPE
> > return pyamf.remoting.encode(pyamf_response, context).getvalue()
> > response._vars=response._caller(gateway)
>
> > It can be seen that in both cases the error arrises in the statement:
> > response._vars=response._caller(...)
> > and involves exactly the same code in pyamf module.
>
> > In httpserver.log I get:
> > 127.0.0.1, 2010-03-09 20:49:52, GET, /AppTryout/rpc/call/amfrpc/test,
> > HTTP/1.1, 500, 4.131000
> > 127.0.0.1, 2010-03-09 20:50:24, GET, /AppTryout/rpc2/gateway/test,
> > HTTP/1.1, 500, 6.098000
>
> > ---------------------------------------------------------------------------
> > --
>
> > My surmise is thay amfrpc won't work with browser, so I prepared
> > simple Flex application to consume these services:
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> > layout="absolute">
> > <mx:Script>
> > <![CDATA[
> > import mx.rpc.events.FaultEvent;
> > import mx.rpc.events.ResultEvent;
> > import mx.controls.Alert;
>
> > private function resultHandler(event:ResultEvent):void
> > {
> > trace(event.result.toString());
> > }
>
> > private function faultHandler(event:FaultEvent):void
> > {
> > trace(event.fault.message);
> > }
>
> > private function fire():void
> > {
> > amfService.test();
> > amfService2.test();
> > }
> > ]]>
> > </mx:Script>
>
> > <mx:RemoteObject id="amfService" showBusyCursor="true"
> > destination="dest-amfrpc">
> > <mx:method name="test" result="resultHandler(event)"
> > fault="faultHandler(event)"/>
> > </mx:RemoteObject>
> > <mx:RemoteObject id="amfService2" showBusyCursor="true"
> > destination="dest-amfrpc2">
> > <mx:method name="test" result="resultHandler(event)"
> > fault="faultHandler(event)"/>
> > </mx:RemoteObject>
> > <mx:Button x="250" y="150" label="Fire" click="fire();"/>
> > </mx:Application>
>
> > ------------
>
> > Its corresponding services-config.xml looks as follows:
>
> > <?xml version="1.0" encoding="UTF-8"?>
> > <services-config>
> > <services>
> > <service id="amfrpc-flashremoting-service"
> > class="flex.messaging.services.RemotingService"
>
> > messageTypes="flex.messaging.messages.RemotingMessage">
> > <destination id="dest-amfrpc">
> > <channels>
> > <channel ref="ch-amfrpc"/>
> > </channels>
> > <properties>
> > <source>*</source>
> > </properties>
> > </destination>
> > <destination id="dest-amfrpc2">
> > <channels>
> > <channel ref="ch-amfrpc2"/>
> > </channels>
> > <properties>
> > <source>*</source>
> > </properties>
> > </destination>
> > </service>
> > </services>
>
> > <channels>
> > <channel-definition id="ch-amfrpc"
> > class="mx.messaging.channels.AMFChannel">
> > <endpoint uri="http://127.0.0.1:8000/AppTryout/rpc/call/
> > amfrpc/test" class="flex.messaging.endpoints.AMFEndpoint"/>
> > </channel-definition>
> > <channel-definition id="ch-amfrpc2"
> > class="mx.messaging.channels.AMFChannel">
> > <endpoint uri="http://127.0.0.1:8000/AppTryout/rpc2/
> > gateway/test" class="flex.messaging.endpoints.AMFEndpoint"/>
> > </channel-definition>
> > </channels>
> > </services-config>
>
> > -------
>
> > When I run the Flex app, I got the follwing trace:
>
> > faultCode:Service.ResourceNotFound faultString:'Unknown service dest-
> > amfrpc.test' faultDetail:''
> > faultCode:Service.ResourceNotFound faultString:'Unknown service dest-
> > amfrpc2.test' faultDetail:''
>
> > But httpserver.log says something else this time:
>
> > 127.0.0.1, 2010-03-09 20:57:22, POST, /AppTryout/rpc/call/amfrpc/test,
> > HTTP/1.1, 200, 4.328000
> > 127.0.0.1, 2010-03-09 20:57:27, POST, /AppTryout/rpc2/gateway/test,
> > HTTP/1.1, 200, 10.093000
>
> > So, Flex reaches the server and gets valid response, but then fails to
> > handle it for some reson.
>
> > At this moment I'm at a loss, because I don't know whether my mistake
> > is at client-side or server-side.
> > Any help will be greatly appreciated.
> > Thanks!
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.