Introduction
MONO is an open source project started in 2001 under the coordination of Ximian, with the purpose of developing an open source, cross platform implementation of the .NET Framework. In this article, I will show the basics of building a distributed application using Mono. The application was written in C# on a RedHat 9 based system. It uses IBM DB2 as a database backend, the SAMPLE database that ships with DB2 and my IBM DB2 open source managed provider (included in the zip attached).
Description
This sample application is divided in 2 conceptual components: a server component accessible using .NET Remoting and a GUI application written in C# with GTK#. I chose to use this GUI toolkit because it is much more flexible and in some points much more mature than Windows.Forms
and it has the big advantage of being truly cross platform. It also has the big advantage of having a really easy to use interface designer - GLADE. The interface is saved in XML based files that can be easily imported in the C# code using the Glade.XML
class. As a matter of fact, you can even define the events your application will handle and specify the functions handling each event, inside GLADE.
For running on a Windows machine, GTK will need the cygwin environment.
The server component is a data source for the client application. To keep the example simple, it only returns an ArrayList
which contains employee related data from the SAMPLE database. The client application will receive this ArrayList
and will insert the employee data in a GtkTreeView
(a flexible equivalent of more Windows.Forms
components, a DataGrid
in this particular case).
Building the code
- The IBM DB2 Managed Provider
On Linux with Mono:
mcs -unsafe -target:library /d:OS_LINUX -r:System.Data.dll
-out:System.Data.Db2Client.dll *.cs
On Windows with Mono:
mcs -unsafe -target:library /d:OS_LINUX -r:System.Data.dll
-out:System.Data.Db2Client.dll *.cs
The managed provider can also be used with Microsoft .NET Framework implementation:
csc -unsafe -target:library /d:OS_LINUX -r:System.Data.dll
-out:System.Data.Db2Client.dll *.cs
- The
EmployeeManager
component mcs -r:System.Data.dll -r:System.Data.Db2Client.dll remotable.cs
- The
server
component: mcs -r:System.Runtime.Remoting.dll -r:remotable.dll server.cs
- The
client
component: mcs -target:exe -resource:db2test.glade -r:remotable.dll
-r:System.Runtime.Remoting.dll -r:gtk-sharp.dll
-r:glade-sharp.dll -out:sample.exe sample.cs
Running the code
- Launch the server:
[db2inst1@linux db2test]$ mono server.exe
The server must be launched by a user that has DB2 rights.
- Launch the client:
mono sample.exe
If you encounter any problems running this sample or if you have any questions related to using mono, please don't hesitate to contact me at victor.vatamanescu @ hqsoftware . ro (spaces are used for spam protection).
Happy hacking!