Macromedia has published an interesting tech note describing how to use CFCs as return types with components called as web services.
One thing to note though - the code in the tech note has a few issues. There are no uses of output=false (which isn't a huge big deal) and no use of the var scope (which is a huge deal).
Either way, it is an interesting article and well worth reading.
Archived Comments
cool until you need to return more than one of anything... most languages don't like CF's inability to specify the type of an array. I think this is a feature that is needed badly. The syntax could be someting like returns="arrayOf(path.to.my.cfc)"
Since Web Services are essentially stateless, the lack of use of 'var' is not important here - each web service call creates a new instance of the CFC to interact with (and then throws it away after the call completes).
I won't deny that it would be better style to use 'var'...
Even though WS are stateless, you can still have var issues. What if you call method Foo(), which makes use of X as a loop iterator. Inside that method you call another method, goo(), which also uses X. Both are not var scoped. Would this not be an issue?
Yes, but the example code doesn't do that...
If you call multiple methods that access the same (variables scope) variable then it will do what you have programmed it to do... If you need X to be a different variable in both Foo() and Goo() you need to program accordingly.
Most folks don't write code that complex so they'll get away with not using 'var' in a web service.
I'm not recommending that style, just pointing out that there's nothing inherently wrong with the example code in the article...
Ah, I guess we will have to agree to disagree. While I agree that the code will work, I would never recommend someone not use the var keyword. It would seem like very bad practice.
I think we're in agreement on the style - as I said "I'm not recommending that style [not using 'var']"...