The following example describes how to call a method from a C# .NET class library that has been created in an external DLL.
1. | In USoft Definer, select RDMI, dotNet Components from the Define menu. |
2. | Create a simple .NET C# component, using the following illustration as an example: |
| NOTE: The Assembly References field should be left empty at this stage. |
3. | Press Commit. USoft compiles this code. |
4. | Press the Check button. The RDMI interface is generated by USoft. If there are already methods and parameters defined, you will be asked if you want to generate a new RDMI interface (the old methods and parameters will be overwritten) or if you just want to check the existing methods and parameters |
5. | In the Application, check the component using the following command in SQL Command: |
invoke myclass.simplecall with select 'simple'
| You should see the result: |
ok: simple
Creating an External Assembly (DLL)
1. | Using, for example, Microsoft Visual Studio 2008 build a simple ‘SimpleRDMI’ project using the following code: |
| NOTE: In Microsoft Visual Studio 2008 you can do this using the following menu sequence File Menu, New Project, Visual C##-, Windows, Class Library. |
using System;
using System.Text;
namespace SimpleRDMI
{
public static class ExtClass
{
public static String Callme(String instr)
{
return "External call :" + instr;
}
}
}
|
3. | Once this project is built copy the resulting SimpleRDMI.dll file to the <USoftInstalldir>\bin folder. |
4. | In the DotNet Components window of the Definer, add the name of the newly created DLL to the ‘Assembly References’ field of the MYCLASS component created earlier. Also provide the identity of the namespace where the component was created, and call the external method in the DLL. Use the following illustration as an example:: |
6. | Press the Check button. |
7. | In the Application, check the component using the following command in SQL Command: |
| invoke myclass.simplecall with select 'simple' |
| You should see the result: |
External call: :simple
Calling the Assembly (DLL) from an alternative location
To make use of an assembly at a location other than the default <usoftinstalldir>/bin folder, you can add it to the Global Assembly Cache (GAC).
1. | Create a strong name for the assembly, using the Microsoft .NET Framework Strong Name Utility (sn.exe). For example: |
| C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe" -k keyPair.snk |
2. | This newly created keyPair.snk file must now be referenced in the SimpleRDMI project Assembly information. In Visual Studio, add the following line to your AssemblyInfo.cs file: |
[assembly: AssemblyKeyFileAttribute("c:\\outside_usoft\\SimpleRDMI\\keyPair.snk")]
4. | This newly created SimpleRDMI assembly must now be added to the Global Assembly Cache. From the Windows Control Panel, Select Administrative Tools, followed by .Net Framework <version> Configuration, My Computer, then Assembly Cache. |
| Right click on the Assembly Cache item, choose Add from the resulting menu, and add the name of the SimpleRDMI assembly. The illustration below shows the Windows 7 Control Panel. |
5. | In the DotNet Components window of the Definer, add the name of the newly created SimpleRDMI.dll file to the ‘Assembly References’ field of the component created earlier. |
7. | Press the Check button. |
8. | Make sure that the original SimpleRDMI.dll file has been removed file from <usoftinstalldir>\bin, and In the application, check that the component still works with the new assembly location by using the following command in SQL Command: |
invoke myclass.simplecall with select 'simple'
| You should see the result: |
External call: :simple
See also
Example: Tracing information from a dotNet application
Defining a component starting from C# code
Defining a component starting from the RDMI interface
|