The answer is by creating a "dll" in .net. Then ColdFusion will access the methods of the dll file by creating Object of that dll.
Example:
Now, I am going to create a Calculator library in .net(a dll file) which will have two methods addition and subtraction using the following .net code.
using System;
namespace Calculator
{
public class Calculator
{
public int addition(int a, int b)
{
return a + b;
}
public int subtraction(int a, int b)
{
return a - b;
}
}
}
Then, I wrote the following lines of ColdFusion code to create object of that ".dll" file.
<cfscript>
variables.dotNetObject = createObject("dotnet", "Calculator", "#expandPath('./Calculator.dll')#").init();
WriteDump(variables.dotNetObject);
</cfscript>
variables.dotNetObject = createObject("dotnet", "Calculator", "#expandPath('./Calculator.dll')#").init();
WriteDump(variables.dotNetObject);
</cfscript>
But, I got the one error message:
"DotNet Side does not seem to be running. Ensure that the DotNet agent is running and you have provided the correct host and port information "
Solution:
1. Go to the window services viewer and see whether "ColdFusion .NET Service" service is running or not. If not running then start the service. If the service is not Present then go to step 3.
2. After that check whether the code is again throwing the same error or not.
3. If it again throwing the same error then go to "http://help.adobe.com/en_US/ColdFusion/9.0/Installing/WSc3ff6d0ea77859461172e0811cdec18969-7ff1.html" and follow the instructions to reinstall/install the ColdFusion .net Service.
After, following all the instructions and reinstalling the ColdFusion .net Service I again run the code. I got the following error:
"Class Calculator not found in the specified assembly list.The assembly that contains the class must be provided to the assembly attribute. "
Solution:-
In the above ColdFusion code, in the function createObject we are passing the class name as "Calculator" in the argument. Our class name in the above .net code is aslo "Calculator". Then what is the cause of the problem???
While creating a .net class we have to specify the name space of that class, if you are not specifying the name space then the Project will be taken as the default name space.
So, in the .net code our name space will be "" and during accesing the class we must have to sppecify the name space like this:"<name-space>.<class>".
In ColdFusion code instead of passing "Calculator" we have to pass "Calculator.Calculator". The out put of the Dump will be as follow:
The dump shows the object have two function addition and subtraction. Now, we can perform the operation like general ColdFusion Object.