Expand my Community achievements bar.

SOLVED

Problems using rpc between Flex and CF

Avatar

Level 2
Hi

I've got a problem sending objects between Flex and
Coldfusion using the AMF Gateway of the newest Coldfusion Version.

The transfer from CFC to Flex does work, but I can't send a
complex object to a CFC.



The error Message is:

faultCode:Client.Message.Encoding faultString:'Cannot create
class of type 'flex.HotlineSystem.bin.cf.Category'.'
faultDetail:'Type 'flex.HotlineSystem.bin.cf.Category' not found.'



Im totally going nuts ... the transfer from CF to Flex is
working fine, the mapping between category.cfc and category.as ist
working. But If I try to send an category Object from Flex to my
CFC it is not.



Hope someone can help.



Merci!



CFC Function:

<cffunction name="insertCategory" access="public"
returntype="void" output="false">

<cfargument name="category"
type="flex.HotlineSystem.bin.cf.Category" required="true">



<cfquery name="insertCategory"
datasource="hotline_system">

INSERT INTO category (category_idCategory, name)

VALUES ( #category.getCategory_IdCategory()#,
'#trim(category.getName())#')

</cfquery>





category.cfc:



<cfcomponent displayname="Category"
alias="flex.HotlineSystem.bin.cf.Category" hint="I model a single
Category">

<cfproperty name="idCategory" type="numeric"
default="0">

<cfproperty name="category_idCategory" type="numeric"
default="0">

<cfproperty name="name" type="string" default="">



<cfscript>

//Initialize the CFC with the default properties values.

variables.idCategory = 0;

variables.category_idCategory = 0;

variables.name = "";

</cfscript>



<cffunction name="init" output="false"
returntype="flex.HotlineSystem.bin.cf.Category">

<cfreturn this>

</cffunction>



<cffunction name="getIdCategory" output="false"
access="public" returntype="any">

<cfreturn variables.IdCategory>

</cffunction>



<cffunction name="setIdCategory" output="false"
access="public" returntype="void">

<cfargument name="val" required="true">

<cfif (IsNumeric(arguments.val)) OR (arguments.val EQ
"")>

<cfset variables.IdCategory = arguments.val>

<cfelse>

<cfthrow message="'#arguments.val#' is not a valid
numeric"/>

</cfif>

</cffunction>



<cffunction name="getCategory_idCategory" output="false"
access="public" returntype="any">

<cfreturn variables.Category_idCategory>

</cffunction>



<cffunction name="setCategory_idCategory" output="false"
access="public" returntype="void">

<cfargument name="val" required="true">

<cfif (IsNumeric(arguments.val)) OR (arguments.val EQ
"")>

<cfset variables.Category_idCategory = arguments.val>

<cfelse>

<cfthrow message="'#arguments.val#' is not a valid
numeric"/>

</cfif>

</cffunction>



<cffunction name="getName" output="false" access="public"
returntype="any">

<cfreturn variables.Name>

</cffunction>



<cffunction name="setName" output="false" access="public"
returntype="void">

<cfargument name="val" required="true">

<cfset variables.Name = arguments.val>

</cffunction>

</cfcomponent>



category.as:



package classes

{

[Bindable]

[RemoteClass(alias="flex.HotlineSystem.bin.cf.Category")]

public dynamic class category

{

public var idCategory:int;

public var category_idCategory:int;

public var name:String;



public function category(){



}



public function fill(idCategory:int,
category_idCategory:int, name:String):void{

this.idCategory = idCategory;

this.category_idCategory = category_idCategory;

this.name = name;

}





public function getIdCategory():int{

return this.idCategory;

}



public function setIdCategory():void{

this.idCategory = idCategory;

}



public function getCategory_IdCategory():int{

return this.category_idCategory;

}



public function
setCategory_IdCategory(category_idCategory:int):void{

this.category_idCategory = category_idCategory;

}



public function setName(name:String):void{

this.name = name;

}



public function getName():String{

return this.name;

}

}

}

1 Accepted Solution

Avatar

Correct answer by
Level 2
Problem solved:

It is apparently not possible to transfer an object of an
action script class to coldfusion.



The solution is to encapsulate the object (in my example
category) in an array.



Strange, ... but it works.



best regards

View solution in original post

6 Replies

Avatar

Former Community Member
The top level flex.* package is reserved for Flex only, you
cannot use this

with ColdFusion CFCs.





Avatar

Former Community Member
That is, try a different package name for your CFCs to
something other than

flex.*



Pete





Avatar

Level 2
Hi

first of all: thanks for replying.



I changed the package to "da.HotlineSystem.bin.cf.Category"
and my webdirectory to
"..\CFusionMX7\wwwroot\da\HotlineSystem\bin\cf", but there is still
the same error message:



faultCode:Client.Message.Encoding faultString:'Cannot create
class of type 'da.HotlineSystem.bin.cf.Category'.'
faultDetail:'Type 'da.HotlineSystem.bin.cf.Category' not found.'



I changed the CFC argument types to any but it makes no
difference.

I think it has something to do with the mapping between the
category.as and the category.cfc



Did I forget anything in my cfc or as files?



Heres my service.config.xml from
CFusionMX7\wwwroot\WEB-INF\flex



<?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>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>

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

<serialization>

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





Avatar

Level 2
Nobody?

hm, .. is it possible to send complex objects from flex to
coldfusion, or is it only possible to consume?

Avatar

Correct answer by
Level 2
Problem solved:

It is apparently not possible to transfer an object of an
action script class to coldfusion.



The solution is to encapsulate the object (in my example
category) in an array.



Strange, ... but it works.



best regards

Avatar

Former Community Member
Ah right, the issue is that ColdFusion supports two styles of
providing arguments

to CFC functions - ordered arguments and named arguments.



If you call your RemoteObject method with a single complex
object it thinks

you are providing a Struct of named arguments. This is a
legacy feature from

the original Flash Remoting functionality and CFCs. There are
several work

arounds... wrapping it in an Array is one such workaround,
another is to

simply provide a second argument so that it will think the
complex object

is just the first ordered argument rather than a struct of
named arguments.