visual-studio-codeamfphpapache-royale

How to use AMFPHP with Apache Royale


I have an issue on using SimpleRemoteObject. (sdk 0.9.6)

My actual website is using this code to call remote function with Amfphp :

<mx:RemoteObject id="ro" source="aadmin" destination="amfphp">
    <mx:method name="siteLogin" fault="{onRcv_siteLoginErr(event)}" result="{onRcv_siteLogin(event)}"/>
</mx:RemoteObject>

As <mx:method/> does't exist in Apache Royale I set this code :

 </js:beads>
        <js:SimpleRemoteObject id="sro" source="aadmin" result="onResult(event)" fault="onFault(event)"
                         endPoint = "http://amfphp.myserver_url.com/gateway.php"
                         destination = "amfphp" />
 </js:beads>

aadmin is my php class service name

To call my function I do :

 sro.send("siteLogin",["123"]);

where siteLogin is my function to call inside aadmin class

Running this, I have this issue :

The class {Amf3Broker} could not be found under the class path {/home/www/amfphp/services/amfphp/Amf3Broker.php}

Why does it show Amf3Broker ? Does anyone have an exemple of working SimpleRemoteObject with amfphp ?

Server side I use https://github.com/silexlabs/amfphp-1.9

Do I need to setup a service-config.xml file ? If yes how to use it with compiler ? (I tried "services": "services-config.xml" in compilerOptions but not working)

Here is my service-config.xml :

<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://amfphp.myserver.com/gateway.php" class="flex.messaging.endpoints.AMFEndpoint"/>
        <properties><add-no-cache-headers>false</add-no-cache-headers></properties>
    </channel-definition>
</channels> 
</services-config>

Now I have do a test with amfphp V2.0 from https://github.com/silexlabs/amfphp-2.0

This is a little better, but I have an error. It seem that there is an issue with _explicitType property. Moreover I don't see my argument ('123') in [requestMessage]

    /onStatusî$flex.messaging.messages.ErrorMessage
correlationId   faultCode@ faultDetailfaultStringvUndefined property: stdClass::$_explicitType . 
<br>file:  /home/www/mysite.com/amfphpv2/Plugins/AmfphpFlexMessaging/AmfphpFlexMessaging.php 
<br>line: 113 
<br>context: Array
(
    [requestMessage] => Amfphp_Core_Amf_Message Object
        (
            [targetUri] => null
            [responseUri] => /1
            [data] => Array
                (
                    [0] => stdClass Object
                        (
                            [body] => stdClass Object
                                (
                                )

                            [clientId] => 
                            [correlationId] => 
                            [destination] => amfphp
                            [headers] => stdClass Object
                                (
                                )

                            [messageId] => EF4BF9E3-5C02-1060-1FF3-5D9781F55A31
                            [operation] => 13
                            [timeToLive] => 0
                            [timestamp] => 0
                        )

                )

        )

    [serviceRouter] => Amfphp_Core_Common_ServiceRouter Object
        (
            [serviceFolders] => Array
                (
                    [0] => /home/www/mysite.com/amfphpv2/Core/../Services/
                )

            [serviceNames2ClassFindInfo] => Array
                (
                    [AmfphpMonitorService] => Amfphp_Core_Common_ClassFindInfo Object
                        (
                            [absolutePath] => /home/www/mysite.com/amfphpv2/Plugins/AmfphpMonitor/AmfphpMonitorService.php
                            [className] => AmfphpMonitorService
                        )

                    [AmfphpDiscoveryService] => Amfphp_Core_Common_ClassFindInfo Object
                        (
                            [absolutePath] => /home/www/mysite.com/amfphpv2/Plugins/AmfphpDiscovery/AmfphpDiscoveryService.php
                            [className] => AmfphpDiscoveryService
                        )

                )

            [checkArgumentCount] => 1
        )

    [explicitTypeField] => _explicitType
)
    rootCause   

Thanks in advance for any help...


Solution

  • Here is some tested working code on 0.9.6 sdk (please notice that you must use config flex to be able to use mx if you have mx library issue). tested with v1.9 and v2.0 AMFPHP from silexlabs :

    <fx:Declarations>
        <mx:RemoteObject id="ro"  result="onResult(event)" fault="onFault(event)" source="your-service-php-class"
                            endpoint = "https://www.your-amfphp-server.com/amfphp/gateway.php"
                            destination = "amfphp" />
    </fx:Declarations>
    

    Then in script

    ro.getOperation("your-php-function-to-call").send("your-param");
    

    [update] Important : be sure to have this in your application else you will have error like *The class {Amf3Broker} could not be found*

    <mx:beads>
        <js:ClassAliasBead />
    </mx:beads>
    

    [update#2] You what to use config royale but also wants MX libs to use MX remote object ? Here is how : https://github.com/apache/royale-asjs/issues/495#issuecomment-539906300