Twitter: raymondcamden

Address: Lafayette, LA, USA

ColdFusion .Net Integration

10-24-2006 26,311 views ColdFusion 11 Comments

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

view plain print about
1<cfobject type=".net" class="xxx" assembly="foo.dll" name="something">
2<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


These comments will soon be imported into Disqus. To add a comment, use Disqus above.
  • Commented on 10-24-2006 at 5:32 PM
    Calling .NET functionality remotely from a CF unix server? Sweet!
  • Charlie Gaddy #
    Commented on 10-24-2006 at 5:58 PM
    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
  • Commented on 10-24-2006 at 7:15 PM
    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....
  • Commented on 10-30-2006 at 8:59 AM
    ryan: well you could via .net objects. Not quite as nice obviously.
  • Andy Burton #
    Commented on 02-06-2007 at 9:35 AM
    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()>
  • James Wood #
    Commented on 02-07-2008 at 12: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.

  • Rich Laird #
    Commented on 06-04-2008 at 12: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
  • Upendra Roul #
    Commented on 03-10-2011 at 1:15 AM
    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 ...

  • Al #
    Commented on 02-07-2012 at 9:15 AM
    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.
  • James Wood #
    Commented on 02-08-2012 at 9:50 AM
    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
  • Al #
    Commented on 02-08-2012 at 3:16 PM
    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.