The Trouble with CF8's .NET Integration

I have an opportunity to take on a project that involves replacing as ASP/AJAX front-end with a Flex front end. The back-end uses .NET Objects, so with CF8's new .NET integration feature, it seems like it should be simple to use CF8 as a middleware to connect directly to the .NET objects I need and then using Flex Remoting

for the Flex front-end.

Before bidding the project, I decided to try to connect to the .NET Object first and access a Playlist class that would provide the Flash Media Server 2 RTMP addresses, and other details about streaming videos that would play on the Flex side. I am more determined than usual to make something new like this work, because this could really open the doors of opportunity for more projects in 2008 and beyond, so I am doing this preliminary experimentation for free (prior to bidding the project) so I can create a more accurate bid.

Ten hours later, I am more perplexed than when I started. The assembly .dll file is completely documented, with a website that lists Classes, Methods, and Properties. The class I want to connect to exists, but the CF8 Error says the method cannot be found.

It was later revealed by the .NET Team who created the .dll assembly that they didn't exactly follow all of the rules when creating the .NET Assembly. It is NOT "strongly named." A .NET Assembly that is strongly named, has a cryptographic key that is generated, along with other .NET specific attributes. Nice! No mention at all in the LiveDocs that the .NET Assemblies you want to connect to have to be "strongly named." (I am sure something that like is assumed, like if you are breathing, it must be air). On the flip side, I sure didn't read anything on the web that a .NET Assembly could be created without it having the criteria that makes it a .NET Assembly (that's something only .NET coders know of and do).

So beware fellow CFers - the Adobe LiveDocs will tell you

"Because you use the .NET assembly classes the same way that you use any other ColdFusion object, you do not have to understand the details of .NET technology; you only have to understand how to use the specific .NET class that you are accessing."
(http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=dotNet_02.html#1160020)
So what's important to note here, is that knowing the right questions to ask about the .NET Assemblies you want to connect to, will undoubtedly save you time and frustration. Hopefully this experience that I have blogged will help you be more efficient with CF8's .NET Integration feature.

I will blog further on this once I get a properly created .NET .dll Assembly to work with. My suspicion is that it will work, as easily as billed by Adobe, once a proper .NET Assembly is provided.

If anyone else out there has experience with this feature, please leave a comment for secrets to success. I am pursuing the simplest solution with a local .NET Assembly using .NET Framework v2.0. The .NET team I am working with was encouraged that we didn't have to use the GAC (Global Assembly Cache) which is an option the LiveDocs lists as an option. I don't know if all .NET Developers have the same attitude of avoiding the GAC, but it might save you some time to ask about it.

Comments
Martin Pitt's Gravatar There a a couple of great solutions out there for .NET / Flex remoting, specifically WebOrb (http://www.themidnightcoders.com/weborb), and the open source equivilant, FluorineFx ( http://www.fluorinefx.com/ ).

Both have support for exactly what you're after, as well as support for the RTMP protocol (though this is more mature in WebOrb than Fluorine at the moment).

Addmitadly, I haven't ever tried the CF approach, (or ever used CF), so I can't offer any insight into the differences.

However, I highly reccomend both of these products, which I've used both extensively.
# Posted By Martin Pitt | 1/6/08 8:07 PM
Charlie K.'s Gravatar Previously, I was developing CF code on BlueDragon, so .NET integration was a piece of cake...but now, I'm working with Adobe folks, so ColdFusion 8 is the app-server of choice.

We need to be able to integrate with NTLM and Active Directory. Using BlueDragon, it was a simple as <Cfset user = #System.Security.Principal#>

Anybody doing anything like this with CF8 and .NET interop?
# Posted By Charlie K. | 1/29/08 10:49 AM
James Wood's Gravatar I too have been frustrated with trying to get the integration to work. We have successfully called and .NET class and returned a query result. BUT, this is only when we have a hard coded connection string. We didn't seem to have to have "strongly named" .dll.

When we try to use the connection string that is defined in the web.config file we get an error that "The ConnectionString property has not been initialized"

If you have any further results then I would be very interested to know what you found.
# Posted By James Wood | 2/6/08 12:50 PM
Kevin Huth's Gravatar First, thanks for the blog!

I've also been trying to get the integration to work. I'm trying to use the System.Messaging dll to write to the Mircosoft Messaging Queue (MSMQ). I can't seem to get CF to find this dll.

I get the following:

Class System.Messaging not found in the specified assembly list. The assembly that contains the class must be provided to the assembly attribute.

When I try to add the assembly attribute (on my server the path is C:\WINNT\assembly\System.Messaging.dll), it says it cannot find it. But I don't think that is really where it live because doing a file search in Windows Explore also won't return an results when searching for the above file in the WINNT directory.

I've also tried to add this assembly using the jnbproxyGui.exe, but it seems to not allow me to build the project.

Any ideas?
# Posted By Kevin Huth | 2/6/08 3:14 PM
James Wood's Gravatar Hi

This is something that I have used to find out the locations of the .dlls

http://www.aisto.com/roeder/dotnet/

It is the Reflector for .NET. A very useful tool for traversing through a dll and finding the classes.

Hope it helps
# Posted By James Wood | 2/6/08 3:19 PM
rafael's Gravatar hi

i made an example on how to use .net + coldfusion... i hope it helps

(it encrypts a string with a Rijndael algorithm 256 bit)

<cfobject type=".NET" name="myRijndael" class="System.Security.Cryptography.RijndaelManaged" assembly="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Security.dll">
<cfobject type=".NET" name="myConvert" class="System.Convert" assembly="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll">
<cfobject type=".NET" name="myCipher" class="System.Security.Cryptography.CipherMode" assembly="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Security.dll">
<cfobject type=".NET" name="myEncoding" class="System.Text.UnicodeEncoding" assembly="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll">

<cfscript>
str = "hello";
key = "vXPlTT0bI2Bd2zPwW2sqRRAn8TQ8YmV/iC4+qQgzeNY=";
myRijndael.Set_Key(myConvert.FromBase64String(key));
myRijndael.Set_Mode(myCipher.ECB);

encryptor = myRijndael.CreateEncryptor();
data = myEncoding.GetBytes(str);
dataEncrypted = encryptor.TransformFinalBlock(data, 0, myEncoding.GetByteCount(str));
returnString = myConvert.ToBase64String(dataEncrypted);
</cfscript>
# Posted By rafael | 8/23/08 12:31 PM
dave's Gravatar I'm loving AJAXCFC, really good work you've done here. I just started on my personal site (http://www.qxiu.net) using AJAXCFC along with the Flickr API, it's turning out to be pretty nice. anyways, just wanted to say thanks for sharing.
# Posted By dave | 10/23/08 2:48 AM
# Posted By olimn | 11/11/08 9:49 PM
Copyright ©2007 JimPickering.com. Some rights reserved. BlogCFC was created by Raymond Camden. This blog is running version 5.1.004.