当我尝试使用正确的远程设置在 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 的配置中,因为这是一个如此简单的请求。