0

当我尝试使用正确的远程设置在 CFC 中调用这个简单函数时,我收到一条错误消息

“目的地‘ColdFusion’要么不存在,要么目的地没有定义通道,并且应用程序没有定义任何默认通道。”

这是CFC,虽然我 99% 肯定它不存在问题,非常简单。

<cfcomponent output="false">

    <!--- Get Server Time --->
    <cffunction name="getServerTime" access="remote" returnType="string">
       <cfreturn now() />
    </cffunction>

    <cffunction name="getString" access="remote" returnType="string">
        <cfreturn "hello......" />
    </cffunction>

</cfcomponent>

这是包含远程调用的main.mxml文件

<?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" viewSourceURL="srcview/index.html" applicationComplete="init()">

<mx:Script>
    <![CDATA[
        import mx.rpc.events.ResultEvent;
        import mx.controls.Alert;

        public function init():void{
          Alert.show(conn.getString());
        }

        public function eventResultHandler(event:ResultEvent):void{
            lblStringResult.text = event.result as String;                 
        }

    ]]>
</mx:Script>

<mx:RemoteObject id="conn" destination="ColdFusion" source="DemoCFC"
    result="eventResultHandler(event)" showBusyCursor="true" >
</mx:RemoteObject>


<mx:Label id="lblStringResult" y="10" horizontalCenter="0"/> 

<mx:Button label="Server Time?.." click="conn.getServerTime();" y="36" horizontalCenter="0" />

</mx:Application>

这是 WEB-INF\flex 文件夹根目录下的services-services.xml文件。对于这个冗长乏味的文件,我深表歉意,但我认为问题可能出在其中。

<services>
    <service-include file-path="remoting-config.xml" />
    <service-include file-path="proxy-config.xml" />
    <service-include file-path="messaging-config.xml" />
</services>

<security>
    <login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>

</security>

<channels>

    <!--  CF Based Endpoints -->
    <!-- {server.name}:{server.port}{context.root} -->
    <channel-definition id="my-cfamf" class="mx.messaging.channels.AMFChannel">
        <endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/" class="coldfusion.flash.messaging.CFAMFEndPoint"/>
        <properties>
            <polling-enabled>false</polling-enabled>
            <serialization>
                <enable-small-messages>false</enable-small-messages>
            </serialization>
            <coldfusion>
                <!-- define the resolution rules and access level of the cfc being invoked -->
                <access>
                    <!-- Use the ColdFusion mappings to find CFCs-->
                    <use-mappings>true</use-mappings>
                    <!-- allow "public and remote" or just "remote" methods to be invoked -->
                    <method-access-level>remote</method-access-level>
                </access>

                <use-accessors>true</use-accessors>

                <use-structs>false</use-structs>

                <serialize-array-to-arraycollection>false
                </serialize-array-to-arraycollection>

                <proxy-load-method>loadProxy</proxy-load-method>

                <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>
            </coldfusion>
        </properties>
    </channel-definition>

    <channel-definition id="cf-polling-amf" class="mx.messaging.channels.AMFChannel">
        <endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/cfamfpolling" class="coldfusion.flash.messaging.CFAMFEndPoint"/>
        <properties>
            <polling-enabled>true</polling-enabled>
            <polling-interval-seconds>8</polling-interval-seconds>
            <serialization>
                <enable-small-messages>false</enable-small-messages>
            </serialization>
            <coldfusion>
                <!-- define the resolution rules and access level of the cfc being invoked -->
                <access>
                    <!-- Use the ColdFusion mappings to find CFCs-->
                    <use-mappings>true</use-mappings>
                    <!-- allow "public and remote" or just "remote" methods to be invoked -->
                    <method-access-level>remote</method-access-level>
                </access>

                <use-accessors>true</use-accessors>

                <use-structs>false</use-structs>

                <serialize-array-to-arraycollection>false
                </serialize-array-to-arraycollection>

                <proxy-load-method>loadProxy</proxy-load-method>

                <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>
            </coldfusion>
        </properties>
    </channel-definition>

    <channel-definition id="my-cfamf-secure" class="mx.messaging.channels.SecureAMFChannel">
        <endpoint uri="https://{server.name}:{server.port}{context.root}/flex2gateway/cfamfsecure" class="coldfusion.flash.messaging.SecureCFAMFEndPoint"/>
        <properties>
            <polling-enabled>false</polling-enabled>
            <add-no-cache-headers>false</add-no-cache-headers>
            <serialization>
                <enable-small-messages>false</enable-small-messages>
            </serialization>
            <coldfusion>
                <!-- define the resolution rules and access level of the cfc being invoked -->
                <access>
                    <!-- Use the ColdFusion mappings to find CFCs-->
                    <use-mappings>true</use-mappings>
                    <!-- allow "public and remote" or just "remote" methods to be invoked -->
                    <method-access-level>remote</method-access-level>
                </access>

                <use-accessors>true</use-accessors>
                <use-structs>false</use-structs>

                <serialize-array-to-arraycollection>false
                </serialize-array-to-arraycollection>

                <proxy-load-method>loadProxy</proxy-load-method>

                <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>
            </coldfusion>
        </properties>
    </channel-definition>

    <!--  Java Based Endpoints -->
    <channel-definition id="java-amf" class="mx.messaging.channels.AMFChannel">
        <endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
    </channel-definition>

    <channel-definition id="java-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
        <endpoint uri="https://{server.name}:{server.port}{context.root}/flex2gateway/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
    </channel-definition>

    <channel-definition id="java-polling-amf" class="mx.messaging.channels.AMFChannel">
        <endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
        <properties>
            <polling-enabled>true</polling-enabled>
            <polling-interval-seconds>8</polling-interval-seconds>
        </properties>
    </channel-definition>

</channels>

<logging>
    <target class="flex.messaging.log.ConsoleTarget" level="Error">
        <properties>
            <prefix>[BlazeDS] </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>
    <manageable>false</manageable>
</system>

这是remoting-config.xml文件。

<?xml version="1.0" encoding="UTF-8"?>

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

<default-channels>
    <channel ref="my-cfamf"/>
</default-channels>

<destination id="ColdFusion">
    <channels>
        <channel ref="my-cfamf"/>
    </channels>
    <properties>
        <source>*</source>
    </properties>
</destination>

当 main.mxml 文件编译运行时,调用 init() 方法,即使用远程对象连接调用 getString() 方法,返回并显示

警报框中的“[object AsyncToken]”。

如果单击该按钮,我将调用方法 getServerTime() 并尝试在 mxml 标签中显示服务器时间,但仅获取

如果我浏览到 ,我会得到一个白页。根据我遇到的一些线程,这应该是一件好事,试图解决这个问题。

main.mxml 文件和 cfc 位于项目的同一文件夹中。所以我知道远程调用正在查找 cfc。

我很确定问题出在 ColdFusion 的配置中,因为这是一个如此简单的请求。

4

1 回答 1

0

您上面的 XML 文件是 services-config.xml,但您在 remoting-config.xml 文件中设置了目标...见下文:

<service id="remoting-service" class="flex.messaging.services.RemotingService">
<adapters>
    <adapter-definition id="cf-object" class="railo.runtime.net.flex.RailoAdapter" default="true"/>
    <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter"/>
</adapters> 
<default-channels>
    <channel ref="my-cfamf"/>
    <channel ref="classic-cfamf"/>
</default-channels>

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

检查您的 WEB-INF/flex 文件夹中的这个文件,并确保您有一个 ColdFusion 目标集,并且它从您上面的 services-config.xml 文件中设置了要使用的适当通道。

很抱歉这么长的回复,但我想我会发布我的 service-config.xml 文件,这样你就可以看到它们是如何协同工作的:

<services-config>

<services>
    <service-include file-path="remoting-config.xml" />
    <service-include file-path="proxy-config.xml" />
    <service-include file-path="messaging-config.xml" />        
</services>

<security>
    <login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>
</security>

<channels>

    <!-- CF -->
    <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>

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

    <channel-definition id="cf-polling-amf" class="mx.messaging.channels.AMFChannel">
        <endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/cfamfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
        <properties>
            <polling-enabled>true</polling-enabled>
            <polling-interval-seconds>8</polling-interval-seconds>
            <serialization>
                <instantiate-types>false</instantiate-types>
            </serialization>
        </properties>
    </channel-definition>

    <channel-definition id="my-cfamf-secure" class="mx.messaging.channels.SecureAMFChannel">
        <endpoint uri="https://{server.name}:{server.port}{context.root}/flex2gateway/cfamfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
        <properties>
            <polling-enabled>false</polling-enabled>
            <add-no-cache-headers>false</add-no-cache-headers>
            <serialization>
                <instantiate-types>false</instantiate-types>
            </serialization>
        </properties>
    </channel-definition>

    <!-- Java -->
    <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
        <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
    </channel-definition>

    <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
        <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
        <properties>
            <add-no-cache-headers>false</add-no-cache-headers>
        </properties>
    </channel-definition>

    <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
        <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
        <properties>
            <polling-enabled>true</polling-enabled>
            <polling-interval-seconds>4</polling-interval-seconds>
        </properties>
    </channel-definition>

    <channel-definition id="my-streaming-amf" class="mx.messaging.channels.StreamingAMFChannel">
      <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure/streamingamf" class="flex.messaging.endpoints.StreamingAMFEndpoint" /> 
      <properties>
        <idle-timeout-minutes>0</idle-timeout-minutes> 
        <max-streaming-clients>100</max-streaming-clients> 
        <server-to-client-heartbeat-millis>5000</server-to-client-heartbeat-millis> 
        <user-agent-settings>
          <user-agent match-on="MSIE" kickstart-bytes="2048" max-streaming-connections-per-session="5" /> 
          <user-agent match-on="Firefox" kickstart-bytes="2048" max-streaming-connections-per-session="5" /> 
          <user-agent match-on="Safari" kickstart-bytes="2048" max-streaming-connections-per-session="5" />
          <user-agent match-on="Opera" kickstart-bytes="2048" max-streaming-connections-per-session="5" />  
        </user-agent-settings>
      </properties>
    </channel-definition>

    <channel-definition id="java-http" class="mx.messaging.channels.HTTPChannel">
        <endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/http" class="flex.messaging.endpoints.HTTPEndpoint"/>
    </channel-definition>

    <channel-definition id="java-secure-http" class="mx.messaging.channels.SecureHTTPChannel">
        <endpoint uri="https://{server.name}:{server.port}{context.root}/flex2gateway/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/>
    </channel-definition>
</channels>

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

<system>
    <redeploy>
        <enabled>false</enabled>
    </redeploy>
</system>

</services-config>
于 2012-06-26T17:09:13.360 回答