Monday, February 24, 2003

Impact of mappings on use of CFCs in CF, web services, and Flash remoting

If you've got code running outside the regular web root on your server, you may know that there are a couple of mechanisms in CF that allow you to create "mappings" to point to those. But what about when you're trying to invoke a CFC, whether with CFINVOKE/CFOBJECT/CreateObject, as a web service, or via Flash Remoting? The two mapping approaches have different fundamental purposes, and also they don't both work for all these attempts you may make to invoke a CFC. I've provided here a "map" (pardon the pun) of what works with what.

First, for background, the first of the two approaches for creating mappings are the CF Admin, which at its core is intended to allow tags like CFINCLUDE and CFMODULE to find CF templates using a mapping, such as to find files outside the webroot or simply to create an alias that facilitates easier reuse among multiple directories. People often get tripped up trying to use this mapping in a URL, which is not it's purpose. It's solely for internal use by CF tags and functions, so it does indeed work for invoking a CFC via CFINVOKE or CFOBJECT/CreateObject. But it doesn't work for invoking the CFC as a web service or via Flash Remoting.

The second approach is to create a virtual directory mapping using CF's underlying jrun-web.xml file. If this is new to you, check out my previous blog entry on the topic. It's easy to do and has value for allowing URLs that point to code outside the webroot or again to create an alias to hide the real directory name. Since it works with URLs, it DOES work for invoking a CFC via web services, but not with CFINVOKE/CFOBJECT/CreateObject, nor via Flash Remoting.

Sadly, it turns out that Flash Remoting doesn't work with either mapping approach, at least in my testing. So the only way to call a CFC via remoting is for it to be in the webroot. I'd welcome any observations others have for finding another solution for that.

To summarize, here's what I've found about invoking CFCs in different ways and with different mappings:

- cfinvoke/cfobject: admin mappings YES, jrun-web.xml mappings NO
- web service: admin mappings NO, jrun-web.xml mappings YES
- flash remoting: admin mappings NO, jrun-web.xml mappings NO

I have only tested this on a server with the built-in web server, so I haven't tested how an IIS virtual directory mapping might affect things, nor how use of IIS may change the nature in which either of these other two mappings are respected.

No comments: