From: Patrick M. <pat...@gm...> - 2007-07-09 05:37:21
|
Well from the look of the AMF packet the PHP side of things is fine, the problem must then lie on the Flex side. Either the RemoteClass tag is not being processed for some reason or the class is imported but not included (you might want to create a dummy TestObj object before calling the remote service, to make sure everything is initialized properly. If not you can try to force the RemoteClass using flash.net.somethingorother, can't remember the name but it's the equivalent of the old Object.registerClass. Patrick Stephen Downs a écrit : > Yeah dumping out evt.result was one of the first things I tried, it is > still giving me just plain old Object and not a TestObj. > > I just installed Charles. Here are the results from testing this test > Flex project, I'm not sure what it means but I can see TestObj class > being targeted (you can see that my object is actually in the > com.visionarium.timesheet package, a bit different from the example > previously posted): > > HTTP/1.1 200 OK > Date: Mon, 09 Jul 2007 05:03:45 GMT > Server: Apache/2.2.3 (Unix) mod_ssl/2.2.3 OpenSSL/0.9.7l DAV/2 PHP/5.1.6 > X-Powered-By: PHP/5.1.6 > Expires: Sun, 8 Jul 2007 22:03:45 GMT > Cache-Control: no-store > Pragma: no-store > Content-length: 357 > Keep-Alive: timeout=5, max=100 > Connection: Keep-Alive > Content-Type: application/x-amf > > PHPSESSID=eb93ffe9a67a0a6c2880e84728bbd803 > Uflex.messaging.messages.AcknowledgeMessagemessageIdI30E0393D-24F1-2308-F39E-00007D2D6B44clientIdI390767D6-4BFE-9109-CB80-00003D24CE2Adestination > bodytimeToLive > correlationIdI2C4D9EDB-2C01-2848-EBC6-A95C9CBB2D3BHTTP/1.1 200 OK > Date: Mon, 09 Jul 2007 05:03:45 GMT > Server: Apache/2.2.3 (Unix) mod_ssl/2.2.3 OpenSSL/0.9.7l DAV/2 PHP/5.1.6 > X-Powered-By: PHP/5.1.6 > Expires: Sun, 8 Jul 2007 22:03:45 GMT > Cache-Control: no-store > Pragma: no-store > Content-length: 417 > Keep-Alive: timeout=5, max=99 > Connection: Keep-Alive > Content-Type: application/x-amf > > PHPSESSID=eb93ffe9a67a0a6c2880e84728bbd803 > Uflex.messaging.messages.AcknowledgeMessagemessageIdI402E5BBE-BAD0-4CA9-F34E-00003F54AB5AclientIdI5788ADD0-6D89-B829-F24F-00003711EDA1destination > body > Ccom.visionarium.timesheet.TestObjtestPropTest prop settimeToLive > correlationIdI233188A8-981C-4A65-A35E-A95C9C9F3 > > > > Thanks very much for the reply Patrick. Amfphp 1.9/2 is really > impressive and helping greatly on my project. > > Steve > > > On 2007-07-08, at 8:40 PM, Patrick Mineault wrote: > >> Hey old mate, >> >> Your code looks good to me, the _explicitType, the RemoteClass, all >> that is fine. I'm thinking it probably has to do with this piece here: >> >> _testObjAC = new ArrayCollection( ArrayUtil.toArray(evt.result) ); >> >> Have you tried simply tracing evt.result is TestObj? >> >> The thing that might help you is looking at it in Charles. Normally it >> should be able to tell you if php has sent back a typed object or a >> dummy object. If it sends back a typed object, then the error is on >> the Flash side, somewhere along the line Flash is not using the >> RemoteClass info for some bizarre reason. Let me know. >> >> Patrick >> >> 2007/7/8, Stephen Downs <st...@pl...>: >>> I'm having a very difficult time understanding why my custom class >>> objects >>> returned from amfphp are being cast as generic Object instances >>> instead of >>> instances of their class. >>> >>> I am using Flex Builder 2, AMFPHP 1.9, and using RemoteObject, which >>> follows >>> Alessandro's terrific example ( >>> http://www.sephiroth.it/tutorials/flashPHP/flex_remoteobject/ >>> ). >>> >>> I set up a project exactly as in Alessandro's example, and the >>> resulting >>> ArrayCollection is properly populated with Person class instances. >>> All well >>> and good. >>> >>> >>> Now I try to create an example from scratch, but it doesn't work. >>> Here's how >>> I set it up (apologies in advance for sending all this code, but I've >>> literally wasted a day and a half trying to fix this): >>> >>> On my server, I have amfphp installed in the amfphp2 directory. My >>> services >>> and php classes are set up as follows: >>> >>> amfphp2/services/com/mycompany/timesheet/TestObjService.php >>> (my service) >>> amfphp2/services/com/mycompany/timesheet/TestObj.php (my >>> custom class) >>> >>> -------------------------------------------------------------------- >>> TestObjService.php: >>> >>> >>> <?php >>> >>> require_once "./TestObj.php"; >>> >>> class TestObjService { >>> >>> function getTestObj() { >>> $tObj = new TestObj(); >>> $tObj->testProp = "Test prop set"; >>> return $tObj; >>> } >>> } >>> >>> >>> -------------------------------------------------------------------- >>> TestObj.php: >>> >>> >>> <?php >>> >>> class TestObj { >>> var $testProp; >>> >>> // explicit actionscript package >>> var $_explicitType = "com.mycompany.timesheet.TestObj"; >>> } >>> >>> ?> >>> >>> -------------------------------------------------------------------- >>> -------------------------------------------------------------------- >>> My Flex Builder project is set up as: >>> >>> Test3/Test3.mxml (Application mxml) >>> Test3/services-config.xml >>> Test3/com/mycompany/timesheet/TestObj.as (AS custom class) >>> >>> -------------------------------------------------------------------- >>> Test3.mxml: >>> >>> >>> <?xml version="1.0" encoding="utf-8"?> >>> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >>> layout="absolute" >>> creationComplete="initApp()"> >>> >>> <mx:RemoteObject id="myService" >>> source="com.mycompany.timesheet.TestObjService" >>> destination="amfphp" showBusyCursor="true" > >>> <mx:method name="getTestObj" >>> result="getTestObjHandler(event)" /> >>> </mx:RemoteObject> >>> >>> >>> <mx:Script> >>> <![CDATA[ >>> >>> >>> import com.mycompany.timesheet.TestObj; >>> import mx.collections.*; >>> import mx.rpc.events.ResultEvent; >>> import mx.utils.ArrayUtil; >>> >>> >>> [Bindable] >>> private var _testObjAC:ArrayCollection; >>> >>> >>> public function initApp():void { >>> myService.getTestObj(); >>> } >>> >>> >>> private function getTestObjHandler(evt:ResultEvent):void >>> { >>> _testObjAC = new ArrayCollection( ArrayUtil.toArray(evt.result) ); >>> // Returns Object instead of TestObj instance! >>> trace(_testObjAC.getItemAt(0)); >>> } >>> >>> >>> ]]> >>> </mx:Script> >>> >>> >>> </mx:Application> >>> >>> -------------------------------------------------------------------- >>> TestObj.as class: >>> >>> >>> package com.mycompany.timesheet { >>> >>> >>> [RemoteClass(alias="com.mycompany.timesheet.TestObj")] >>> [Bindable] >>> public class TestObj { >>> public var testProp:String; >>> } >>> >>> >>> } >>> >>> >>> -------------------------------------------------------------------- >>> services-config.xml (this same file works using Alessandro's example): >>> >>> >>> <?xml version="1.0" encoding="UTF-8"?> >>> <services-config> >>> <services> >>> <service id="amfphp-flashremoting-service" >>> class="flex.messaging.services.RemotingService" >>> messageTypes="flex.messaging.messages.RemotingMessage"> >>> <destination id="amfphp"> >>> <channels> >>> <channel ref="my-amfphp"/> >>> </channels> >>> <properties> >>> <source>*</source> >>> </properties> >>> </destination> >>> </service> >>> </services> >>> <channels> >>> <channel-definition id="my-amfphp" >>> class="mx.messaging.channels.AMFChannel"> >>> <endpoint uri="http://localhost/amfphp2/gateway.php" >>> class="flex.messaging.endpoints.AMFEndpoint"/> >>> </channel-definition> >>> </channels> >>> </services-config> >>> >>> >>> -------------------------------------------------------------------- >>> -------------------------------------------------------------------- >>> Additional notes: >>> >>> The compiler arguments for Test3.mxml are set to: >>> -locale en_US -services "services-config.xml" >>> >>> >>> For now I'll have to parse through the resulting array and cast each >>> item to >>> my custom class in AS. Not an ideal option. >>> >>> Thanks for any input. >>> Steve >>> >>> >>> ------------------------------------------------------------------------- >>> >>> This SF.net email is sponsored by DB2 Express >>> Download DB2 Express C - the FREE version of DB2 express and take >>> control of your XML. No limits. Just data. Click to get it now. >>> http://sourceforge.net/powerbar/db2/ >>> _______________________________________________ >>> amfphp-general mailing list >>> amf...@li... >>> https://lists.sourceforge.net/lists/listinfo/amfphp-general >>> >>> >> >> ------------------------------------------------------------------------- >> >> This SF.net email is sponsored by DB2 Express >> Download DB2 Express C - the FREE version of DB2 express and take >> control of your XML. No limits. Just data. Click to get it now. >> http://sourceforge.net/powerbar/db2/ >> _______________________________________________ >> amfphp-general mailing list >> amf...@li... >> https://lists.sourceforge.net/lists/listinfo/amfphp-general > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > ------------------------------------------------------------------------ > > _______________________________________________ > amfphp-general mailing list > amf...@li... > https://lists.sourceforge.net/lists/listinfo/amfphp-general > |