What is the proper way to pass an entire form to a webservice? I can make a my
CFC work with 1 param, which is the FORM, but when I try to use the CFC as a
webservice I get a type mismatch error. The has to be a way to pass the entire
form to a webservice rather than me, creating a bunch of params for each form
element, I just can not find an example anywhere. I know I can not be the only
person ever to ask this question.
Bash - 26 Jun 2007 16:58 GMT
How are you invoking the webservice?
Did you set a data type for the expected argument in the cfc? If so, what
type did you use?
Using cfinvoke you can use the argumentscollection attribute. If using
createObject you can pass the form as a structure.

Signature
Bryan Ashcraft (remove BRAIN to reply)
Web Application Developer
Wright Medical Technology, Inc.
-------------------------------------------------------------------------
Macromedia Certified Dreamweaver Developer
Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/
programmer_neo - 26 Jun 2007 17:06 GMT
Yes, I wrote the service, and was passing it to a STRUCT type. I never use the
argumentscollection, I always just pass the FORM thru a cfinvokeargument.
One way I know I can do it, is to use CFWDDX and serialize the FORM, then pass
it in as a STRING, then once in the webservice, i use CFWDDX again an
deserialize it back into a struct.
I am just wondering if this is the only way. I'd think there'd be a better way.
Bash - 26 Jun 2007 17:12 GMT
Hmm. I've never had a problem passing the form struct into a webservice.
What is the exact error message you are getting?

Signature
Bryan Ashcraft (remove BRAIN to reply)
Web Application Developer
Wright Medical Technology, Inc.
-------------------------------------------------------------------------
Macromedia Certified Dreamweaver Developer
Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/
programmer_neo - 26 Jun 2007 17:32 GMT
I get a Java error ... something to the effect ... a Type Mismatch.
Bash - 26 Jun 2007 19:47 GMT
And you're positive it is the invocation causing the error and not something
else in the cfc or calling page?

Signature
Bryan Ashcraft (remove BRAIN to reply)
Web Application Developer
Wright Medical Technology, Inc.
-------------------------------------------------------------------------
Macromedia Certified Dreamweaver Developer
Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/
>I get a Java error ... something to the effect ... a Type Mismatch.
programmer_neo - 26 Jun 2007 20:07 GMT
Yes I am positive.
Have you successfully passed a FORM to a webservice through cfinvoke as a
cfinvokeargument parameter?
(And before anyone askes, no it is not a caching problem, I run a script to
destroy the stub. To me, CF is not handling the FORM scope as expected. Rather
than treating it as a STRUCT, it thinks it is something else.)
cf_dev2 - 26 Jun 2007 20:17 GMT
Technically I think FORM is not the same type of structure as StructNew(). I don't know if that's the problem, as Bash said he's had no problem with it.
programmer_neo - 26 Jun 2007 20:20 GMT
I'm sure that is the problem. I'd bet FORM is an OBJECT.
In short, then how do I pass it in?
cf_dev2 - 26 Jun 2007 20:48 GMT
Yes, they're both objects, just different types
FORM is: coldfusion.filter.FormScope
StructNew() produces: coldfusion.runtime.Struct
I think you're right. I tried a simple webservice and it threw
"java.lang.IllegalArgumentException: argument type mismatch"
It works if I use Duplicate(form). That function must return a regular
structure.
cf_dev2 - 26 Jun 2007 20:53 GMT
..
<cfinvoke webservice="http://localhost/TestWebService.cfc?wsdl"
method="testStructure"
returnvariable="output">
<cfinvokeargument name="formStructure" value="#Duplicate(form)#">
</cfinvoke>
<cfdump var="#output#">
<!--- TestWebService --->
<cfcomponent >
<cffunction name="testStructure" access="remote" returntype="struct"
output="no">
<cfargument name="formStructure" type="struct" required="yes">
<cfset var outStructure = StructNew()>
<cfset outStructure.foundKeys = structKeyList(arguments.formStructure)>
<cfreturn outStructure/>
</cffunction>
</cfcomponent>
programmer_neo - 26 Jun 2007 21:13 GMT
Wow, cool, I'll have to try that. I never really used Duplicate(). I just
thought it was used to un-associate a pointer from the original object. I never
had a need for that.
That will work better for me than to use WDDX
cf_dev2 - 26 Jun 2007 21:20 GMT
Yep, I use it for that purpose frequently. Figured it was worth a shot. Seems to do the trick.
programmer_neo - 26 Jun 2007 21:22 GMT
BKBK - 27 Jun 2007 15:19 GMT
Why not go all the way and harvest the whole form with:
<!--- TestWebService --->
<cfcomponent >
<cffunction name="testStructure" access="remote" returntype="struct"
output="no">
<cfargument name="formStructure" type="struct" required="yes">
<cfset var outStructure = StructNew()>
<cfset outStructure = duplicate(arguments.formStructure)>
<cfreturn outStructure/>
</cffunction>
</cfcomponent>
cf_dev2 - 27 Jun 2007 17:56 GMT
No reason other than personal preference. I wanted a quick test that proved the function was able to read the argument structure but did something different than just echoing the form structure.
BKBK - 29 Jun 2007 10:55 GMT
Cf_dev2 wrote:
[i]No reason other than personal preference. [/i]
Fair enough. Yeh pays yer money, yeh makes yer choice.