ColdFusion .Net Integration

This post is more than 2 years old.

Again - forgive the haphazard nature of the notes.

.Net Integration Session

Why? Leverage functionality available in .Net. Leverage MS products like Word, Excel, Outlook, etc.

Idea is to keep it simple. (Like rest of ColdFusion.) Right now you can talk to .Net using web services (if the .Net code is available via web services.) With Scorpio you will be able to do it directly.

How can we interact with .Net?
Web Services (available now)
Using COM
Runtime Unification (new in Scorpio)

Runtime Unification:
Make .net components locally available. Invoke .net components directly from CFM. Using cfobject and createObject. Works very much like cfobject/createobject for Java

<cfobject type=".net" class="xxx" assembly="foo.dll" name="something"> <cfset foo = something.method>

Web Services versus RU:

Loose coupling versus tight coupling.
Coarse granular and less programmatic control versus fine granular and more programmatic control.
Low on performance/realiability versus better performance/reliability.
Stateless versus Stateful.
Web services more useful for external clients where RU is better for internal clients.

Seamless (no configuration)
Location independent (components can be remote or local)
Platform independent (CF can be on any platform calling .Net on a Windows platform)
Hot deployment of assemblies.
Can talk to multiple .net servers.
Automatic conversion from/to basic CF datatypes and .Net datatypes.

cfobject: class, name, assembly, protocol, secure, server, port

For assembly, can be a list of exe's or dlls or proxy jars. mscorlib.dll always included.

For protocol, binary is default with best performance. HTTP can be used across the net.

For constructors, you manually call init() after the cfobject call.

For static methods, no need to call init.

Example shows getting running processes via .Net. Next example is creating Word docs via ColdFusion.

For datatypes - decimal type not supported. You can use JavaCast on the CF side. JavaCast updated to support byte, short, and char. They have a full mapping of .Net to Java conversions. (Too much to type.)

A proxy is used to handle communication. This means that if you are on a non-Windows machine, must use a command line tool to create the proxies. Proxies generated for .Net 1.x can be used for 2.0 as well. Proxies generated for 2.0 can only be used for 2.0.

Deploment scenario: .net and cf on same machine - no configuration - simplest.

CF and .Net on 2 different machines. The ".Net Side Agent" needs to be installed on other machine and you have to register the assemblies that CF will have access too.

CF on non-Windows machine. .Net side agent needs to be installed on the .Net machine. Generate proxy. This is done on .Net machine and you copy the generated JAR to the CF machine.

Limitations: Enum and Decimal data type not supported.
Methods with out parameters as arguments.
Methods with pointers as arguments or return type.
.Net UI components

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Tony Brandner posted on 10/25/2006 at 2:32 AM

Calling .NET functionality remotely from a CF unix server? Sweet!

Comment 2 by Charlie Gaddy posted on 10/25/2006 at 2:58 AM

ColdFusion .NET Integration

* Equal adoption of J2EE and .Net in marketplace.
* In CF7 - use Webservices to communicate with .net components.
* MSIL - intermediate lang. like class file in Java
* CLR is JVM - memory, threads, etc.
* Assembly - Packaged form of class files - .dll or exe
* Clobal assembly cache - All apps running on machine can access assembly cache
* CF interop strategies
o Web Services - Communicate using Soap XML packets
o Messaging - JMS< MQSeries - Event Gateways
o COM - Create COM wrapper to .net assemply. Create Java proxy and invke from CF. Complex.
o Runtime Unification (Scorpio) - Make .net components locally available. Invoke .net components from CFML. cfobject type=".net" class="" assembly="" name="" />. Provides tight coupling, granular control, performance, stateful, for use in internal enterprises.
o Location independent, platform independent, hot deployment
* mscorlib.dll assembly will always be included
* assembly - list of dll/exes and/or proxy jars.
* protocol - binary (default, better perf.) or http (can be used across firewall)
* constructors - use init and pass constructor args
* static method - no need to init() to call static method
* Call methods on object just like any other
* accessing public fields
* Used to generate Word doc
* Automatic conversion of primitive .net datatypes to cf java datatypes to .net
* use javacast if required
* datatype mapping

Comment 3 by Ryan Guill posted on 10/25/2006 at 4:15 AM

whoa wait a second, you mean we are going to be able to have runtime unification of .net objects on a separate server?? We can't even do that with cfc's....

Comment 4 by Raymond Camden posted on 10/30/2006 at 7:59 PM

ryan: well you could via .net objects. Not quite as nice obviously.

Comment 5 by Andy Burton posted on 2/6/2007 at 8:35 PM

I'm sorry I missed this session at the conference; I've been in the BD world of late, and am a bit behind the times on what Scorpio is bringing to the table.

Is their .NET integration something they're pulling off in a similar fashion as New Atlanta does (they recompiled their Java app server using J#)? Or is Adobe using their existing Java-based engine and adding extensions to talk to .NET?

In other words... will they have separate ColdFusion/Java and ColdFusion/.NET products, or one product that does both?

Could I create a page that does something like:

<cfobject type="java" name="jObj" ...>
<cfobject type=".net" name="nObj" ...>
<cfset myValue = jObj.getSomething() + nObj.getSomething()>

Comment 6 by James Wood posted on 2/7/2008 at 11:18 PM

After a good amount of trial and error, we have been able to pull back data from a simple .NET class. The problem that we seem to be having is that unless the .NET connectionString is hardcoded into the class then it won’t work.

The .NET section of our company have already created a plethora of classes and inside these classes they are referencing the connectionString thus:

string connectionString = ConfigurationManager.AppSettings["sqlDatabaseServer"];

This, I am told, is the standard way that .NET works, by putting the string into the web.config file. This would seem to be akin to putting the datasource inside the Application.cfc.

So I suppose my question is twofold.

1. Is it possible to use a connectionString that isn’t hardcoded into the class
2. If so, do we have to somehow instantiate the web.config from ColdFusion first.


Comment 7 by Rich Laird posted on 6/4/2008 at 9:29 PM

James Wood...

Yes, you can use a Connection String in a configuration file with the Cold Fusion 8 java bridge. But it won't be a "web.config" because the bridge doesn't run in a ASP.NET process. If your machine is set up like mine is (I just ran the Cold Fusion 8 installer with all the defaults), it is hosted by a service process.

On my machine, the config file for that process is C:\ColdFusion8\jnbridge\JNBDotNetSide.exe.config. If you add the appSettings collection plus the add statement for the appSetting you are using with the connection string, I believe that will work.

What might be preferable (and I know will work because I tested it) is to follow the convention of using the connectionStrings collection instead of appSettings. In the config file, it looks something like this...

<add name="SPIRE" connectionString="Password=xxxxxx;User ID=xxxxx;Data Source=SPRTEST"></add>

With C# code, you access the connection string like this...

String cnn=ConfigurationManager.ConnectionStrings["SPIRE"].ToString();

As you may know, this statment requires 1) a "using" statement for the System.Configuration namespace and 2) that your assembly references System.Configuration.dll.

Best of luck,
Rich Laird

Comment 8 by Upendra Roul posted on 3/10/2011 at 12:15 PM

Hello All,
I am accessing .net web service from coldfusion but each time it is showing "Web service operation ... with parameters {} cannot be found".In my wsdl the argument type is complex to the specified function .
Please suggest ...


Comment 9 by Al posted on 2/7/2012 at 8:15 PM

I am struggling with the app.config file, similar to James Wood above. I have tried doing what Rich suggested however I must be doing it wrong. It isn't working.

I am using ColdFusion 9,0,1,274733
Somethings work kind of others not so much.

This part work and dumps out all the methods:
<cfobject type = ".NET" name="objClient" class="CompanyInfo.Clients" assembly="E:\Websites\dotNet\Clients.dll,E:\Websites\dotNet\Geneology.dll,E:\Websites\dotNet\ClientsDL.dll,E:\Websites\dotNet\GeneologyDL.dll" protocol = "tcp" action = "create" secure = "false">

<cfdump var="#objClient#">

However when I attempt to use a method like:

<cfset fullClientName = objClient.Get_Clientname("21024641")>

I get an error:

ClassName: objClient
Detail: The assembly that contains the class must be provided to the assembly attribute.
Message: Class objClient not found in the specified assembly list.

I am guessing that this is due to the app.config file not being part of what I am doing. I have tried to put the lines below in the JNBDotNetSide.exe.config file in several different places. When I restart the CF .Net service I get errors saying that the dot net service isn't running or it has no positive effect on the error above.

<add name="ClientSQLConnection" connectionString="Integrated Security=SSPI;Initial Catalog=ClientSQL;Data Source=SERVER5;Connect Timeout=0"/>
<add name="FourthShiftConnection" connectionString="Integrated Security=SSPI;Initial Catalog=ClientSQL;Data Source=SERVER5;Connect Timeout=0"/> </connectionStrings>

I think perhaps I am misunderstanding the statement above:"If you add the appSettings collection plus the add statement for the appSetting you are using with the connection string". Is that part of the JNBDotNetSide.exe.config file? Where would I put that? Is there an example of how it would be formatted?

Things like (<cfobject type=".NET" name="variables.test" class="System.Net.Dns" action="create" />
<cfset variables.hostName = variables.test.GetHostName() />
<cfoutput><p> Hostname #variables.hostName#</p></cfoutput>) work great, No problem.

The dot net guys are telling me to build in C# and skip ColdFusion, I would like to avoid that. Thank you for any help.

Comment 10 by James Wood posted on 2/8/2012 at 8:50 PM

Hi Al

Have you tried putting the dll files in the same folder as the JNBDotNetSide.exe.config file. For us that was the ColdFusion9DotNetService folder (well actually we put then in a Bin folder in there to try to keep things tidy).
Then reference the dll in the config folder, thus

<section name="ams" type="Name of classes"/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin"/>

This is how we got it to work for us.

Hope this helps

Comment 11 by Al posted on 2/9/2012 at 2:16 AM

I have now placed the dlls in a directory "C:\ColdFusion9\jnbridge\bin" The jnbridge directory is where our JNBDotNetSide.exe.config lives.

I have think I have added the configuration in the right places and restared CF. This is a cut and paste of the JNBDotNetSide.exe.config file:
<?xml version="1.0" encoding="utf-8" ?>
<sectionGroup name="jnbridge">
<section name="dotNetToJavaConfig"
<section name="javaToDotNetConfig"
<section name="tcpNoDelay"
<section name="javaSideDeclarations"
<section name="assemblyList"
type="com.jnbridge.jnbcore.AssemblyListHandler, JNBShare"/>
<!-- I added the objClient Feb 22 2012 -->
<section name="objClient" type="GeneologyDL, ClientDL, Geneology, Client"/>
<!-- I added the runtime Feb 22 2012-->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin"/>

<dotNetToJavaConfig scheme="jtcp" host="localhost" port="6087"/>
<javaToDotNetConfig scheme="jtcp" port="6088"/>
<!-- optional list of .NET-side assemblies -->

Am I doing the "type" correctly? I am thinking it isn't because I am still getting "The assembly that contains the class must be provided to the assembly attribute."

Once they are in the JNBDotNetSide.exe.config correctly - how do I use them? Am I right thining I would use cfobject like this:
<cfobject type = ".NET" name="objClient" class="Client.IBO"
assembly= "C:\ColdFusion9\jnbridge\bin\Client.dll,C:\ColdFusion9\jnbridge\bin\Geneology.dll,C:\ColdFusion9\jnbridge\bin\ClientDL.dll,C:\ColdFusion9\jnbridge\bin\GeneologyDL.dll" />

Client Name:#objClient.Get_ClientName("21024641")#

I really appreciate all of your help.

Comment 12 (In reply to #7) by PizzaTheHutt posted on 4/10/2015 at 4:09 PM

7 years later, but a HUGE thank you to you for this!!