|
SYS-CON Magazines
|
Top Three Links You Must Click On
Mono Getting Started in Linux for the Experienced .NET Developer
Get your applications ready for the world's fastest-growing OS
By: Richard K. Blum
Nov. 10, 2005 08:45 AM
The GTK# classes are used in the Linux world. They use the GIMP GTK+ libraries, which are most commonly found in the GNOME desktop environment, although they can also be loaded on systems using the KDE desktop. The GTK# classes provide a simplified way of producing .NET applications for the Linux environment, although they are obviously not compatible with the Windows environment. If you are writing applications specifically for the Linux platform, the GTK# classes are a great tool to use.
ASP.NET Support The development environment for ASP.NET is normally the Windows IIS Web server; however this server is not portable to Linux. Instead, Mono provides two alternative solutions to this problem. The first option is an ASP.NET plug-in module for the Apache Web server. The Apache Web server is the most popular Web server used on the Linux platform. The Mono mod_mono Apache module provides the necessary ASP.NET functions to an existing Linux Apache server. For high-volume server applications, this is the way to go. The second option is a stand-alone ASP.NET server called XSP. The XSP project provides a complete Web server written in C# code. It's not ideal for larger applications, but it works fine for most small- and medium-sized situations. Since it is written in C# code, it's completely portable to the Windows platform. It can run on either Linux or Windows as an ASP.NET Web server. Both mod_mono and XSP provide support for standard ASP.NET Web forms and Web services. Let's test out a Web service project to see how it works. Listing 2, MathService.asmx, is a program I used in my C# Network Programming book to illustrate a basic Web service program. It creates a Web service that supplies four math methods - addition, subtraction, multiplication, and division. Create the MathService.asmx program in a test directory on your Linux server. From the test directory, start XSP by typing xsp on the command line. The XSP server starts and tells you the listening address (it uses address 0.0.0.0 to indicate it is listening to all addresses on the server) and the port it uses (by default, port 8080). You can test the Web service by connecting to it with a browser, as shown in Figure 1. Now it's time to create the Web service proxy. Just as in .NET, Mono provides the WSDL program to connect to a Web service, and create the .cs file with the proxy methods. The command line format is: $ wsdl http://localhost:8080/MathService.asmx This creates the MathService.cs file. After the file is generated, you can create a proxy library file for the Web service: $ mcs /t:library MathService.cs This creates the MathService.dll program. This Web proxy client program can be used on both Windows and Linux clients. Now let's create a client program to use the proxy. Listing 3 shows the ServiceTest.cs program. It uses the MathService class to utilize the Web service methods. Compile the client program using the command line: $ mcs /r:System.Web.Service.dll /r:MathService.dll ServiceTest.cs You must include the System.Web.Service library as well as the specific Web service proxy library file. The resulting program is ServiceTest.exe. Running the program produces the expected results from the Web service server:
$ mono ServiceTest.exe 100 50
What About an IDE? Monodevelop is a graphical IDE environment for creating C# and GTK# applications. While it's not as advanced as Visual Studio, it does have many of those features with which you are already familiar. When starting a new project in Monodevelop, a wizard dialog displays that asks you to select the project type. When you select a project type and name, a rough code template is created for you, as shown in Figure 2. Select the project type you're interested in, type in a name for your project, and away you go. As you type in your program, monodevelop tracks the variables, methods, and classes created. Figure 3 shows the SampleClass.cs program from Listing 1 as a console project.
Summary Reader Feedback: Page 1 of 1
Subscribe to our RSS feeds now and receive the next article instantly!
Subscribe to the World's Most Powerful Newsletters
|
|
||||||||||||||||||||||||||||||||||||||||||||