13 Replies Latest reply on May 4, 2009 8:18 PM by Peter Farland

    RemoteObject

    ProjectedSurplus Level 1

      Excuse the rant but I wouldn't have ever believed I was so incredibly stupid until I tried to pick up flex. FWIW I started to write out my questions but between the 8 different posts I've tried to implement  don't even know where to start (cross domain, RDS, CF channel definition, flex2gateway . . . )

       

      So, while paying homage to how incredibly cool it was to drag my first component onto the Design panel . . . . I can't get even a Hello World RemoteObject tutorial to work (albeit after having to wade through HTTPS, SOAP etc to guess that my knowledge of DW and CF makes RO the best option).

       

      Now, admittedly I am attempting the apparently never before considered strategy of NOT using a coldfusion localhost NOR the Create CFC Coldfusion Wizard but why won't this work??? Thanks in advance,

       

      1.  Create new Flex project (does it have to list the CF application server/why can't a remote object just connect remotely to a cfc?)

      2.  Create helloWorld.cfc and I assume put it on network CFserver

       

      <cfcomponent>
      <cffunction name="GetHello" output="false" access="remote" returntype="string">
          <cfreturn "Hello World">
          </cffunction>
      </cfcomponent>

       

       

      3.  In Main.mxml create

       

      <?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. ResultEvent;
              import mx.utils.ObjectUtil;
         
          private function GetHello_handler(event:ResultEvent):void {
              Result.text = ObjectUtil.toString(event.result);
              }
          ]]>
      </mx:Script>

       

      <mx:RemoteObject id="helloWorld" destination="Coldfusion" source="test.helloworld">
          <mx:method name="GetHello" result="GetHello_handler(event)" />
      </mx:RemoteObject>

       


      <mx:Label id="Result" x="59" y="58"/>
      <mx:Button x="154" y="56" label="Get Hello" click="helloWorld.GetHello()"/>

       

      4.  ([RPC Fault faultString="[MessagingError message='Destination 'Coldfusion' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']" faultCode="InvokeFailed" faultDetail="Couldn't establish a connection to 'Coldfusion'"])

        • 1. Re: RemoteObject
          Michael Borbor Level 4

          Hi there, you have to configure the server technology at the project declaration so the Flex will be able to know a few addresses and embed that data in the compile app. That's not a must , you can also go along with creating a simple project and doing what this tutorial explains.

           

           

          Mike Nimer's Blog: Bye bye -services!

          1 person found this helpful
          • 2. Re: RemoteObject
            ProjectedSurplus Level 1

            First, thanks for the reply.  Second, so from what I can infer there are multiple strategies and various setting requirements.  Can anybody point to or provide a resource that explains the options?  Per my original post I literally have played with so many different settings (config etc) that I don't really know where I would be starting from anymore were I to follow another post.  Thanks in advance.

            • 3. Re: RemoteObject
              Michael Borbor Level 4

              You could just create a flex

              Project without server technology and then in your CF remote object 

              set an endpoint there was a recent thread about this too you could 

              find that one useful.

               

              Sincerely,

               

              Michael

               

              El 27/04/2009, a las 20:37, ProjectedSurplus <forums@adobe.com

              escribió:

               

              >

              First, thanks for the reply.  Second, so from what I can infer there 

              are multiple strategies and various setting requirements.  Can 

              anybody point to or provide a resource that explains the options?  

              Per my original post I literally have played with so many different 

              settings (config etc) that I don't really know where I would be 

              starting from anymore were I to follow another post.  Thanks in 

              advance.

              >

              • 4. Re: RemoteObject - STILL LOST
                ProjectedSurplus Level 1

                OK, so fresh install CF8 on my workstation (btw administrator will not display for some reason but that's just my life ) but still no joy whatsoever.  

                 

                http://localhost:8500/    shows Index of  and includes (amongst a tonne of shrapnel from various attempts):

                •      HelloWorld.cfc
                •      crossdomain.xml
                •      Test2Connect/
                •      Test2Connect-debug/ 

                 

                (Fwiw I also have a network and internet connected CF8-IIS webserver at     http://xx.xx.xx.247:8500/  showing a crossdomain.xml and various directories containing working cfcs/cfms/htmls).

                 

                 

                Now, to my (lack of) understanding, I need a "flex2gateway" which a search of the directories is NOT on either machine atm.  Where do I get/install this and how do I create/adjust settings?????

                 

                Further, am I correct in assuming I need to set {server.name}:{server.port}{context.root} in my services-config.xml (in C:\ColdFusion8\wwwroot\WEB-INF\flex) which is currently (and if so what do I set it to insofar as I can do server name and port but what is the context root?):       

                 

                <!--  CF Based Endpoints -->
                        <channel-definition id="my-cfamf" class="mx.messaging.channels.AMFChannel">
                            <endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/" class="flex.messaging.endpoints.AMFEndpoint"/>
                            <properties>
                                <polling-enabled>false</polling-enabled>
                                <serialization>
                                    <instantiate-types>false</instantiate-types>
                                </serialization>
                            </properties>
                        </channel-definition>

                 

                Again, thanks in advance and apologies for being apparently the stupidest person on earth.

                • 5. Re: RemoteObject - STILL LOST
                  ProjectedSurplus Level 1

                  OK, on the 6th page of google results I have found this:

                   

                  http://www.frenches.com/blog/index.cfm/2007/5/7/Flex-Coldfusion--Dont-make-me-have-to-sepa rate-you-two

                   

                  No idea where it will lead (just reading now) but per Jerry Maguire, it had me at "Warning:  I'm about to rant."

                  • 6. Re: RemoteObject - STILL LOST
                    Michael Borbor Level 4

                    The Flex2Gateway is configured by default in CF, you just need to set your Remote object endpoint to http;//localhost:8500/flex2gateway or whatever address your server has and then in source especify the address to your CFCs.

                    • 7. Re: RemoteObject
                      Peter Farland Level 3

                      This is a J2EE concept.  /flex2gateway is a servlet mapping and is defined in your web application's /WEB-INF/web.xml file. The application server intercepts URL requests for you web application and those URLs with this servlet mapping will be processed by the flex2 gateway servlet. It does not represent a physical directory.

                       

                      (I'm guessing the * characters are to add emphasis in your email and that they're not actually in your /WEB-INF/flex/services-config.xml as they shouldn't be there?)

                       

                      The context root is another J2EE concept. In the following URL, the context root is /myapp

                      http://somecompany.com:5100/myapp/flex2gateway

                       

                      It provides a scope to the application server to direct the request to a particular web application deployed to /myapp. Depending on how you deployed your application, this may or may not be a physical directory.

                       

                      If you deployed your application to the default context-root of "" (i.e. the empty string), it wouldn't appear in your URL and you'd just have a servlet mapping after the host and port:

                       

                      http://somecompany.com:5100/flex2gateway

                       

                      So, while the client and substitute values for {server.name} and {server.port} based on what was used to load the SWF, it cannot substitute the {context.root} token as it does not know whether the section following the host and port is a directory, servlet mapping or context root. This means when compiling a Flex application, if your configuration makes use of the {context.root} token, in addition to pointing the compiler to your /WEB-INF/flex/services-config.xml file with the -services option you also need to tell it what the context-root is using the --context-root option.

                       

                      mxmlc.exe -services=path/to/myapp/WEB-INF/flex/services-config.xml -context-root=/myapp SomeDataDrivenApplication.mxml

                       

                      If you know that you're only going to deploy your application in one configuration, you could just remove the {context.root} token from your services-config.xml - if your application is deployed to the default context root "", then just remove the token (otherwise you'll need to add in the relevant piece of the URL, i.e. /myapp).

                       

                               

                       

                      Pete

                      1 person found this helpful
                      • 8. Re: RemoteObject - STILL LOST
                        ProjectedSurplus Level 1

                        OK, the following connects to an internet based CF8-IIS server (albeit with    <cross-domain-policy>     <allow-access-from domain="*" />    </cross-domain-policy> in that server's wwwroot folder -- but I will worry about that next month).  Moreover note that Properties >> Flex Compiler >> Additional compiler arguments = -locale en_US

                         

                        <?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.ResultEvent;
                                    import mx.controls.Alert;
                                   
                                    [Bindable]
                                    public var sResult:String;
                                   
                                    public function handleStringResult(event:ResultEvent):void{
                                        sResult=event.result as String;   
                                    }
                                
                                ]]>
                            </mx:Script>

                           
                            <mx:RemoteObject id="svcColdFusion"      destination="ColdFusion"       endpoint="http://xx.xx.xx.xx:8500/flex2gateway/"
                                 source="test.helloworld" > 

                                     <mx:method name="GetHello"       result="handleStringResult(event)"          fault="Alert.show(event.fault.message)" />

                               
                            </mx:RemoteObject>

                         

                            <mx:Label id="lblStringResult" text="{sResult}" x="145" y="10"/>   
                            <mx:Button label="get String Remote Object" click="svcColdFusion.GetHello()" x="83" y="78"/>
                           
                        </mx:Application>

                         

                        FB3 does however report: "The services configuration includes a channel-definition 'my-cfamf-secure' that has an endpoint with a context.root token but a context root has not been defined. Please specify a context-root compiler argument.".  I'm going to play around with this minor victory and report back (for the benefit of future path followers) but comments/guidelines/feedback on limitations/security issues/alternative suggestions would still be appreciated.

                        • 9. Re: RemoteObject
                          Michael Borbor Level 4

                          Have you checked the status of the Flex Integration in the CF administrator?

                          • 10. Re: RemoteObject
                            ProjectedSurplus Level 1
                            1. Don't really know what you are getting at with "status of the Flex Integration in the CF administrator?"
                            2. Imported Flex proj to a different dev machineand don't have the error any longer in any case.
                            3. Per playing around with previous code, the following also works to send/receive via CFC:

                             

                            -----------------------------------------

                            <?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.collections.ArrayCollection;
                                        import mx.rpc.events.ResultEvent;
                                        import mx.controls.Alert;
                                       
                                        [Bindable]
                                        public var sResult:ArrayCollection;
                                       
                                        public function handleResult(event:ResultEvent):void{
                                            sResult=event.result as ArrayCollection;   
                                        }
                                    
                                         public function onFault(event:FaultEvent):void
                                         { Alert.show("the sky is falling"); }
                                    
                                    ]]>
                                </mx:Script>
                                   
                                <mx:RemoteObject id="svcColdFusion"
                                    destination="ColdFusion"
                                    endpoint="http://xx.xx.xx.xx:8500/flex2gateway/"
                                     source="OnlineOffice.cfc.LangCodeTest"
                                      showBusyCursor="true"> 

                                    <mx:method name="Labels"
                                    result="handleResult(event)" 
                                    fault="onFault(event)" />

                             

                                   
                                </mx:RemoteObject>
                               
                            <mx:Panel width="100%" height="100%">
                                <mx:DataGrid id="mygrid" dataProvider="{svcColdFusion.Labels.lastResult}" width="100%" height="100%"/>   
                                <mx:Button label="Hit CFC" click="svcColdFusion.Labels('en')"/>

                             

                            </mx:Panel>
                               
                            </mx:Application>

                            • 11. Re: RemoteObject
                              Michael Borbor Level 4

                              Cool so it's working now. In CF 8 there's an option to turn on/off the

                              CF/Flex integration, but in your case seems like the flex-config.xml has

                              some issues, or your project set-up wasn't the right one.

                              • 12. Re: RemoteObject - STILL LOST
                                Muzak Level 3

                                FB3 does however report: "The services configuration includes a channel-definition 'my-cfamf-secure' that has an endpoint with a context.root token but a context root has not been defined.

                                Add an empty context root to the project compiler options.

                                To do so, open the projects properties, select "Flex Compiler" and in the "Additional Compiler Arguments" field add:

                                 

                                -context-root ""

                                 

                                Click Apply and close the project properties.

                                • 13. Re: RemoteObject
                                  Peter Farland Level 3

                                  Flex's channels send requests to the server using a single protocol by design. e.g. the AMFChannel sends AMF formatted requests using "http". The SecureAMFChannel sends AMF formatted requests using "https".

                                   

                                  If you use <mx:RemoteObject>'s endpoint="..." attribute, it will use the SecureAMFChannel if the URL starts with https:// or it will use the AMFChannel if the URL starts with http://.

                                   

                                  So, if you don't plan on using https, you could comment out the secure-amf-channel, otherwise  remove the {context.root} tokens, or just specify the --context-root="" on the command line config if you leave the token in.