Novell Home

Taking the Leap Without the .NET (Part 1)

Novell Cool Solutions: Feature
By Richard Smith

Digg This - Slashdot This

Posted: 5 Dec 2003
 

So what about .NET and Windows and Linux?
During the last couple of years there has been a significant amount of fanfare around Microsoft's .NET technologies, products, and tools. The basis for .NET is the Framework upon which it is built and which allows application developers to easily leverage the service of this Framework. In many developer's minds this is a significant benefit since many of the needed low-level services are built as part of this underlying Framework.

One other important aspect of the foundation for .NET is the ability to create applications in any number of different programming languages and have those applications easily deployed and executed on top of the Framework. With standardized interfaces to these services and the ability to build pieces of the application in different languages, .NET would appear to be a developer's dream come true.

In many respects it is. But with ease of use also comes limitations. As designed, .NET will only execute on Microsoft's Windows platforms. Because one of the most important aspects of .NET development relies on web delivery, many developers are reluctant to invest heavily in .NET until they see some improvements in security on the systems used for deployment. Building and deploying even an outstanding solution can quickly be overshadowed if the application is compromised by vulnerable systems software.

For some time Linux has been a popular choice for deployment and delivery of web applications and services due to a large degree to the more robust and secure infrastructure of the operating system. Linux provides developers not only with a number of security options, but by its nature of being an open, standards based operating system, it also allows developers more ability to enhance the security themselves. If you don't feel that Linux is secure enough, make it more secure by contributing to the operating system source.

So we have a full featured development and deployment Framework in .NET and a developer friendly operating system platform in Linux, but the two are not designed to integrate. Well, at least not until the Mono Project (http://www.go-mono.com) came along. Begun by Ximian the Mono Project is an Open Source alternative to Microsoft's .NET Framework.

Enter the Mono Project
So, Microsoft did do a very good thing as far as .NET goes by submitting portions of the technologies that make up .NET to ECMA for consideration as standards. The Mono Project is the open source effort to not only provide Linux but also other UNIX-based operating systems with access to these technologies. As a result of the efforts of the Mono Project team and other contributors, developers and users now have cross platform options for developing and implementing solutions based on the .NET technologies. Project Mono has also extended the base .NET foundation to include other key solutions technologies including CORBA and LDAP.

Now you ask what does all this have to do with Novell? As you hopefully know, earlier this year Novell purchased Ximian Software, the primary sponsor of the Mono Project. Novell is committed to providing support for open source development and specifically the Mono Project. There are plans for providing additional services around the Mono Project including support and consulting. Novell is also involved in providing resources for contributors by way of Novell Forge (http://forge.novell.com) which will become the home for many Mono based projects and a community around Mono.

What does the Mono Project have to offer?
The central technologies provided as part of the Mono Project are the Common Language Infrastructure (CLI), a class library that works with the CLI and a basic C# language compiler. C# is a new language developed by Microsoft to take advantage of .NET and some of the strengths of previous programming languages. When you look at C# you notice similarities with many other languages including C, C++, Java, and Visual Basic. C#, though, is just one of many languages that are currently available to be used with .NET. There are variations of Pascal, Java, PHP, and Python among others that allow developers to build applications in their language of choice and then deploy that solution on an implementation of the .NET Framework.

The Mono Project is by no means complete, but there is more than enough implemented to allow for significant development and testing. If you have fully .NET compliant application you should be able to deploy them on a Mono setup today with a few caveats. If your application uses only the defined APIs from the SYSTEM namespace, you should be able to use it as is. Care must be taken that your application doesn't use any Win32 system calls.

Mono can host ASP.NET applications right out of the box as will be illustrated later in this article. Mono provides a web hosting server that will serve ASP.NET pages for you. There are also options for using Apache via mod_mono (to be covered in the next installment of this series) which is also available for download from the Mono Project site. We'll get into the XSP web hosting server in a minute and actually set it up and use it to deliver the sample ASP.NET code that installs with Mono.

Other technologies current under development for the Mono Project include ADO.NET and GUI applications. The beginnings of the ADO.NET foundation are in place and you can begin to develop database applications right now. We will tackle this in a future article, detailing the use of open source databases within the Mono framework.

The development of GUI applications is a bit more complicated since Microsoft's GUI implementation, Windows Forms, is partially built on a Win32 foundation. To build GUI applications for Mono using GTK#, which is built on the GTK+ Toolkit, allows the development of native Gnome applications for the Linux desktop. Any development of Windows Forms will take shape using one of the Linux Win32 projects, WINE, to allow compatibility with Windows developed GUI applications.

This really just touches on the scope of the Mono Project. The potential for what can be achieved by the Mono Project is tremendous. As with any Open Source project, Mono relies heavily on contributions from developers all over the world.

Let's see it in action!
In order to see Mono in action you will need a machine with a distribution of Linux installed and working (although you can download and install a version of Mono on Windows if you would like.) You will need to download the files appropriate for you distributions. For our example here we will be using SUSE. We go to the Mono Project web site and under the Downloads (http://go-mono.com/download.html) area we download the following 2 files to our Home directory:

  • mono-0.28-1.ximian.7.1.i586.rpm
  • mono-devel-0.28-1.ximian.7.1.i586.rpm

In addition to the two files from the Mono Project web site you will also need to download an installation for Gtk#. You can download it from SourceForge at http://gtk-sharp.sourceforge.net/. For our use we download gtk-sharp-0.11-1.i386.rpm. This is downloaded to our Home directory.

Using the RPM tool in SUSE install the three packages using the following commands in a terminal session from within our Home directory:

  • RPM –ivh mono-0.28-1.ximian.7.1.i586.rpm
  • RPM –ivh mono-devel-0.28-1.ximian.7.1.i586.rpm
  • RPM –ivh gtk-sharp-0.11-1.i386.rpm

Before we proceed, let's test our installation of Mono to make certain it is working.

  1. Open a console session.
  2. Create a source code file using your editor of choice naming the file HelloCool.cs. Enter the following code into the file:
  3. class HelloCool 
    	using System;
    class HelloCool 
    {
    public static void Main(String[] args) 
    			{
    			Console.WriteLine("Hello Cools!!");
    			}
    } 
    
  4. After saving the file in your home directory under the name HelloCool.cs, enter the following command at the prompt in the terminal session:
    /opt/gnome2/bin/mcs HelloCool.cs
  5. After a couple of seconds you should see the message "Compilation succeeded" and be returned to the command prompt.
  6. At the command prompt enter the following command:
    /opt/gnome2/bin/mono HelloCool.exe
  7. The following should appear:
    Hello Cools !!

Here is a screen shot of what you should see.

These steps have insured that the Mono infrastructure is installed and functioning.

Now that Mono is working, let's do a little more
Next you will need to download the XSP web hosting server from the Mono Project web site. The file we will use is http://www.go-mono.com/archive/xsp-0.6.tar.gz. We download this file to our Home directory also. Then within a terminal session in our Home directory execute the following commands:

  • tar –xzvf xsp-0.6.tar.gz
  • cp –r * /opt/gnome2

This will install all of the necessary files to try out the XSP server and the ASP.NET sample files that install with Mono. To test the ASP.NET sample files provided with XSP enter the following commands in a terminal session:

  • export PATH=$PATH:/opt/gnome2/bin
  • cd /opt/gnome2/share/doc/xsp/test

The first command puts /opt/gnome2/bin in the path allowing for the execution of the Mono runtime without need to enter the complete path. The second command makes the directory holding the sample ASP.NET files the current directory. Now enter the following command from the command line within the /opt/gnome2/share/doc/xsp/test directory:

  • mono /opt/gnome2/bin/xsp.exe

This will launch the XSP server with the Mono runtime and prepare it to serve the ASP.NET files.

Now launch a web browser and enter the URL of http://localhost:8080. You should see something similar to the following screen capture.

TThe XSP server is now delivering ASP.NET pages to your browser. You can launch all of these sample ASP.NET pages and see some of the capabilities provided by ASP.NET as part of Mono.

If you select the calendar.aspx link from this page you will see the following screen.

Since calendar is a built in function of ASP.NET, the code to create this page is fairly simple. Here is the source code for calendar.aspx.

<%@ Page Language = "C#" %>
<html>
<head>
<title>Testing properties in inner tags</title>
</head>
<body>
	<form runat=server>
		<h3>Calendar and properties</h3>
		<asp:calendar id="Calendar1"
		Font-Name="Arial" showtitle="true"
		runat="server">
			<SelectedDayStyle BackColor="Blue" 
					ForeColor="Red"/>
			<TodayDayStyle BackColor="#CCAACC" 
					ForeColor="#000000"/>
		</asp:Calendar>

	</form>
</body>
</html>

You can review the source code for all of the samples included to get an idea of the power of delivering web content using Mono.

This will give you a working Mono system with which to play and familiarize yourself with building simple ASP.NET content. Examine the included source code and check out some of the links below to find out more about Mono, .NET and ASP.NET. As you discover, extend, fix or otherwise mess with the code let us know what you did (cooldev@novell.com), we'd love to see lots of feedback on how you use Mono.

What's coming up next
Next month we'll look at adding support for Apache and MySQL to your Mono system and how they can be leveraged to add more powerful means of delivering web content. In future months we'll examine the recently release C# LDAP libraries and explore some of the many Mono based project available. If you want to get involved in the Mono Project find the links on the Mono web site. You might also find an interesting Mono related project on the Novell Forge site. Links are included below.

Useful Links


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell