18 Replies Latest reply on May 10, 2007 10:37 AM by BLXWebMaster

    not connecting to coldfusion

    splitzer Level 1
      hi,
      for some reason i cant get connected to coldfusion components. Here is the services-config.xml for review:
      <?xml version="1.0" encoding="UTF-8"?>
      <services-config>

      <services>
      <service id="coldfusion-flashremoting-service"
      class="flex.messaging.services.RemotingService"
      messageTypes="flex.messaging.messages.RemotingMessage">

      <adapters>
      <adapter-definition id="cf-object" class="coldfusion.flash.messaging.ColdFusionAdapter" default="true"/>
      </adapters>

      <destination id="ColdFusion">
      <channels>
      <channel ref="my-cfamf"/>
      </channels>
      <properties>
      <source>*</source>
      <!-- define the resolution rules and access level of the cfc being invoked -->
      <access>
      <!-- Use the ColdFusion mappings to find CFCs, by default only CFC files under your webroot can be found. -->
      <use-mappings>false</use-mappings>
      <!-- allow "public and remote" or just "remote" methods to be invoked -->
      <method-access-level>remote</method-access-level>
      </access>

      <property-case>
      <!-- cfc property names -->
      <force-cfc-lowercase>false</force-cfc-lowercase>
      <!-- Query column names -->
      <force-query-lowercase>false</force-query-lowercase>
      <!-- struct keys -->
      <force-struct-lowercase>false</force-struct-lowercase>
      </property-case>
      </properties>
      </destination>

      </service>
      </services>

      <channels>
      <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>
      </channels>

      <logging>
      <target class="flex.messaging.log.ConsoleTarget" level="Error">
      <properties>
      <prefix>[Flex] </prefix>
      <includeDate>false</includeDate>
      <includeTime>false</includeTime>
      <includeLevel>false</includeLevel>
      <includeCategory>false</includeCategory>
      </properties>
      <filters>
      <pattern>Endpoint.*</pattern>
      <pattern>Service.*</pattern>
      <pattern>Configuration</pattern>
      <pattern>Message.*</pattern>
      </filters>
      </target>
      </logging>

      <system>
      </system>

      </services-config>



      CFC file:
      <cfcomponent extends="Service">

      <cffunction name="helloWorld" access="remote" returntype="string">
      <cfreturn "This string came from the remote method">
      </cffunction>
      </cfcomponent>




      MXML file:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical">

      <mx:RemoteObject id="cfService"
      destination="ColdFusion"
      source="lesson5.MyService"/>

      <mx:Button label="Call ColdFusion" click="(cfService.helloworld)"/>

      </mx:Application>


      Can someone please take a look at it and spot any problems?

      Thanks!
        • 1. Re: not connecting to coldfusion
          splitzer Level 1
          anyone?
          • 2. Re: not connecting to coldfusion
            BLXWebMaster
            You need to send your request.

            <mx:Button label="Call ColdFusion" click="(cfService.helloworld.send())"/>

            • 3. Re: not connecting to coldfusion
              splitzer Level 1
              blxwebmaster, i tried adding that also, but it didnt work. Also, i tried importing sample coldfusion/flex apps into flex builder, than tried running it and those apps didnt work either. Do you think maybe someting wrong with my installation or someting? I never got cf/flex worked out.
              • 4. Re: not connecting to coldfusion
                BLXWebMaster Level 1
                O.K. A couple of things.
                1. You are not calling the method in your RO object.

                I also noticed that you are not Using ColdFusion mappings as noted in your config file.
                <use-mappings>false</use-mappings>

                This means that you must make sure that your Flex Application is at the Root of your webserver and you are using dot notation correctly.

                You Have
                <mx:RemoteObject id="cfService" destination="ColdFusion" source="lesson5.MyService"/>

                Which means your CFC must be locations at
                {Webserver Root}/lesson5.MyService.

                If your application is not located in the Root, I suggest using CF Mappings. This will also give you great flexibility as to where you actucally place your Flex App.

                In case you are not versed in CF Mappings. Go to CF Administrtor and create Mapping that points to your directory where your CFC resides. Name the mapping something like "MyFlexApp".

                Then moddify your config xml file and change <use-mappings>true</use-mappings> and restart CF.

                Then modify your remote object to be
                <mx:RemoteObject id="cfService"
                destination="ColdFusion"
                source="MyFlexApp.MyService"/>

                Here is an updated componenet with the correct syntax. This should get you going.

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application
                xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientColors="[#ffffff, #ffffff]">

                <mx:Script>
                <![CDATA[
                import mx.collections.*;
                import mx.rpc.events.*;
                import mx.events.*;
                import mx.controls.*;

                [Bindable]
                public var sResult:String;
                private function helloWorldReceived(event:ResultEvent):void{
                sResult=event.result as String;
                Alert.show("Got it");
                }

                ]]>
                </mx:Script>

                <mx:RemoteObject id="cfService" showBusyCursor="true" destination="ColdFusion" source="MyFlexApp.MyService">
                <mx:method name="helloWorld" result="helloWorldReceived(event)"/>
                </mx:RemoteObject>

                <mx:Button label="Call ColdFusion" click="(cfService.helloworld.send())" x="266" y="24"/>
                <mx:Label text="Result:" x="266" y="54" fontWeight="bold"/>
                <mx:Text x="319" y="54" text="{sResult}" id="textResult"/>

                </mx:Application>

                Let me know how it works out.

                Allen







                • 5. not connecting to coldfusion
                  splitzer Level 1
                  Allen, first of all thanks for helping.

                  For some reason it still didnt work. Here are the steps i took:
                  1. created mapping with following: /MyFlexApp with directory path:C:\CFusionMX7\wwwroot\MyFlexApp

                  2. updated services-config file to use with mapping:
                  <use-mappings>true</use-mappings>

                  3.restarted my coldfusion server service

                  4. updated the code, and tried to run it as you mentioned

                  It didnt work, it just showed the browsing cursor and it stopped. Anything i missed?

                  Some extra details about my computer:
                  CF 7.02, Flex 2, Vista
                  • 6. Re: not connecting to coldfusion
                    BLXWebMaster Level 1
                    Are you running CF on IIS or with it's built in web server? If you are running IIS, move your application into the IIS root. I typically do not run my Websites under the CF directory and don't think it is good practice or will work correctly.

                    So it would go to C:\inetpub\wwwroot\MyFlexApp. Then update your Mapping in CF Administrator. Might be a security issue or something.

                    Also, lets make sure it works under CF.

                    Place this file in the same directory as your MyService.cfc. Then simply open your browser and browse to the file. Http://127.0.0.1/MyFlexApp/Test.cfm.

                    <!--- Test.cfm --->
                    <cfinvoke component="MyService" method="helloWorld" returnvariable="sResult"/>
                    <cfoutput>#sResult#</cfoutput>

                    This will at least make sure CF is installed correctly and your CFC is functioning correctly.

                    Allen


                    • 7. Re: not connecting to coldfusion
                      splitzer Level 1
                      Allen, I have built in CF server installed. Also, the mapping is working correctly, i tested with test.cfm and it did return the result what was expected.

                      The coldfusion is working properly, i think there is someting wrong with the connection between flex/CF.
                      • 8. Re: not connecting to coldfusion
                        splitzer Level 1
                        do you think that SDK has to do someting with this? I dont have that installed.
                        • 9. Re: not connecting to coldfusion
                          splitzer Level 1
                          any other ideas? I'll try to reinstall flex, lets see if that works.
                          • 10. Re: not connecting to coldfusion
                            BLXWebMaster Level 1
                            O.K. So CF is working and your CFC works.

                            What error are you recieving exactly?

                            Also, make sure you can access the Flex Gateway correctly.

                            You should be able to browse to this page and get a blank page. If you get anything other then a blank page, that is a problem. Keep working on it until you get the blank page.

                            http://{server.name}:{server.port}{context.root}/flex2gateway/

                            If you are running IIS this should be something like.

                            http://127.0.0.1/flex2gateway/


                            Allen
                            • 11. not connecting to coldfusion
                              splitzer Level 1
                              Allen, i tried to open http://localhost:8500/flex2gateway/ and i got a blank page.

                              Also, i reinstalled flex 2, reinstalled sdk. Tested the project and it still didnt work.


                              About the error, i dont receive any erros. It doesnt do anyting at all. It changes the cursor to loading (clock) sign, and it changes back to regular mouse. No errors at all.
                              • 12. Re: not connecting to coldfusion
                                BLXWebMaster Level 1
                                O.K. Lets try this....

                                Add this line in you CFC and see if the function is at least being executed. Run your app and check for the written file.

                                <cffile action="WRITE" file="C:\test.txt" output="CFC Executed OK" addnewline="Yes" fixnewline="No">

                                Let me know what happens.
                                Allen
                                • 13. Re: not connecting to coldfusion
                                  splitzer Level 1
                                  added that line at the bottom of cfc, it created a new file under C drive with the text CFC Executed OK.

                                  • 14. Re: not connecting to coldfusion
                                    BLXWebMaster Level 1
                                    Do me a favor and send me your complete MXML & CFC and I will run it locally here and see if anything jumps out. I am dizzy.

                                    AL
                                    • 15. Re: not connecting to coldfusion
                                      splitzer Level 1
                                      cfc:
                                      <cfcomponent>

                                      <cffunction name="helloWorld" access="remote" returntype="string">
                                      <cfreturn "This string came from the remote method">
                                      </cffunction>

                                      <cffile action="WRITE" file="C:\test.txt" output="CFC Executed OK" addnewline="Yes" fixnewline="No">

                                      </cfcomponent>

                                      MXML:
                                      <?xml version="1.0" encoding="utf-8"?>
                                      <mx:Application
                                      xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientColors="[#ffffff, #ffffff]">

                                      <mx:Script>
                                      <![CDATA[
                                      import mx.collections.*;
                                      import mx.rpc.events.*;
                                      import mx.events.*;
                                      import mx.controls.*;

                                      [Bindable]
                                      public var sResult:String;
                                      private function helloWorldReceived(event:ResultEvent):void{
                                      sResult=event.result as String;
                                      Alert.show("Got it");
                                      }

                                      ]]>
                                      </mx:Script>

                                      <mx:RemoteObject id="cfService" showBusyCursor="true" destination="ColdFusion" source="MyFlexApp.MyService">
                                      <mx:method name="helloWorld" result="helloWorldReceived(event)"/>
                                      </mx:RemoteObject>

                                      <mx:Button label="Call ColdFusion" click="(cfService.helloworld.send())" x="266" y="24"/>
                                      <mx:Label text="Result:" x="266" y="54" fontWeight="bold"/>
                                      <mx:Text x="319" y="54" text="{sResult}" id="textResult"/>

                                      </mx:Application>
                                      • 16. Re: not connecting to coldfusion
                                        BLXWebMaster Level 1
                                        Hymm,

                                        Well I think we might have done a lot of needless running around. I am not sure about this, however the click event should call a function. Your sample did in fact not work for me, but I made a slight modification and everythign works on my end.

                                        Here is the updated code.

                                        Note: I used the endpoint tag in my remote object, you might not need it depending on your config.

                                        Let me know if we are done.

                                        Allen


                                        <?xml version="1.0" encoding="utf-8"?>
                                        <mx:Application
                                        xmlns:mx=" http://www.adobe.com/2006/mxml"
                                        layout="absolute"
                                        backgroundGradientColors="[#ffffff, #ffffff]">

                                        <mx:Script>
                                        <![CDATA[
                                        import mx.collections.*;
                                        import mx.rpc.events.*;
                                        import mx.events.*;
                                        import mx.controls.*;

                                        [Bindable]
                                        public var sResult:String;

                                        private function Test():void{
                                        cfService.helloWorld.send();
                                        }
                                        private function helloWorldReceived(event:ResultEvent):void{
                                        sResult=event.result as String;
                                        }
                                        ]]>
                                        </mx:Script>

                                        <mx:RemoteObject endpoint=" http://127.0.0.1/flex2gateway/" id="cfService" showBusyCursor="true" destination="ColdFusion" source="MyFlexApp.MyService">
                                        <mx:method name="helloWorld" result="helloWorldReceived(event)"/>
                                        </mx:RemoteObject>

                                        <mx:Button label="Call ColdFusion" click="Test();" x="266" y="24"/>
                                        <mx:Label text="Result:" x="266" y="54" fontWeight="bold"/>
                                        <mx:Text x="319" y="54" text="{sResult}" id="textResult"/>
                                        </mx:Application>

                                        • 17. not connecting to coldfusion
                                          splitzer Level 1
                                          hey Allen, it worked! yea man, finally it worked. I think we had to mention endpoint in the remoteobject or someting. But the modified code you gave made it work. I'll look into details later on.

                                          Thank you,!!
                                          • 18. Re: not connecting to coldfusion
                                            BLXWebMaster Level 1
                                            Your welcome. Good luck.

                                            Al