asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Developing Web Applications for .NET and J2EE Using a Single Source Strategy
By Marco Nanni
Rating: 4.6 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Introduction


    Portability is a feature that can notably improve the market share of a software product. The ASP.NET technology allows the development of web applications that are browser independent but it limits the application to running inside an IIS web server.

    The Mono project allows the execution of these applications on other web servers. It implements a Common Language Runtime that allows the execution of these applications on non-Microsoft systems without re-compiling the code. Mono does this by implementing a custom application server and as a result doesn't allow the execution of these applications inside a 3rd party application server.

    Enter Visual MainWin from Mainsoft. Visual MainWin introduces a new C# or VB.NET compiler that allows the generation of Java bytecode. In this way these applications can run inside the traditional applications server (JBoss, WebSphere, etc.) increasing notably the application portability.

    What is Visual MainWin?

    Visual MainWin for J2EE Developer Edition, also known as "Grasshopper", is a Visual Studio .NET plug-in that Mainsoft freely delivers through its own site devoted to the developers: http://dev.mainsoft.com.

    Visual MainWin enables developers to create applications for the J2EE platform using C# or VB.NET that reference the ASP.NET and ADO.NET class libraries. It is a complete development solution that includes:

    • A development environment integrated into Visual Studio .NET that can be used to develop, deploy, and debug J2EE applications.
    • A set of Java runtime libraries (mainly derived from the Mono project) that enable applications to run on a J2EE application server.

    The commercial version of Visual MainWin, named Enterprise Edition, supports more application servers, allows the debugging of the native Java library, and presents other advanced functionalities. MainSoft guarantees and supports only the Enterprise Edition. For further information about the differences between the free and the commercial versions, see http://www.mainsoft.com/products/vmw_j2ee.aspx.

    During the tests I have used the trial of Visual MainWin Enterprise Edition rel. 1.6.0.56 on Windows XP using SQL Server 2000.

    Visual MainWin allows the development of C# or VB applications in two ways:

    1. Native J2EE: the C# or VB code is compiled only for J2EE platform; to do this, we have to open a new "Visual MainWin C # or VB for J2EE Project" using the wizard shown in the following figure:

    2. Single Source Development: this way allows the generation of executable code for both the .NET and J2EE platform.

    During the tests I have used the 2nd way.

    Visual MainWin supports the main J2EE Application Servers (the possible use of EJB is limited to JBoss, WebSphere and WebLogic) and several DBMSs: Oracle, SQLServer, PostgreSQL, DB2, Sybase.

    How Does It Work?

    Visual MainWin introduces a patent-pending technology, that enables the binary compilation of Microsoft Intermediate Language (MSIL) into standard Java bytecode. Developers can write programs in C# or VB and then compile their source code directly into standard Java bytecode.

    The following figure (derived from the Mainsoft documentation) shows this compilation process.


    Binary compilation from MS Intermediate Language to Java bytecode

    Practically, the binary compiler then reads the .NET assemblies and generates Java bytecode.

    Unlike the standard Microsoft compiler that produces a single DLL for each project, this new compilation process produces one DLL (and then a class files) to correspond to every C# source files. Subsequently, these class files are linked inside a single Jar, War or Ear file. For more information about the compilation process, please see: http://dev.mainsoft.com/Default.aspx?tabid=32&src=Overview.html

    The Visual MainWin compilation process produces an application (Jar, War, Ear) structurally equal to what we can get with the compilation of a Java source file. The only difference is the language used to write it. Nevertheless, the transformation of the DLLs into Java byte code is not enough to produce a working application. In fact the original application references several class libraries that are not implemented in the J2EE platform. Therefore, Visual MainWin provides a Java implementation of the ASP.NET and ADO.NET class libraries based on the Mono project. Mainsoft also developed a thin hosting layer on top of J2EE in order to bind the Mono class libraries to the services supplied by the J2EE platform:

    • ASP.NET HTTP layer uses servlets
    • ADO.NET database connectivity uses JDBC
    • Web service clients use Java sockets
    • Web services use servlets

    The following figure (derived from the Mainsoft documentation) shows the class library architecture.


    Runtime libraries stack

    Visual MainWin uses some Mono components, but it is very different from Mono. In fact, Mono offers the partial implementation of the .NET framework class library and provides a custom version of the Common Language RunTime for the execution of .NET applications. Practically, Mono implements a its own custom Application Server. Contrarily, Visual MainWin produces J2EE applications whose execution uses the traditional J2EE Application Server.

    Single Source Development

    After having opened an ASP.NET solution, we can select the project folder in solution explorer and then we can run the option "Generate J2EE project".

    This option creates a second project with the J2EE extension inside the same solution. All the references of the original project (aspx pages, web-reference, etc.) are cloned in the second project. Additionally, it creates some new folders that contain specific files for the J2EE platform. Particularly:

    • the "assembly" folder contains the temporary class files;
    • the "Web-INF" folder contains the web.xml file for the application configuration for Tomcat;
    • the " bin_Java" folder contains the war file for the application deployment (we have a jar file if the .NET project produces a simple DLL library).

    The option "Generate J2EE project" produces a second project inside a single solution. The source files are physically shared, but the project files are separated; this means that if we add a web page in the original project, we must repeat this operation inside the J2EE project. As a rule, the addition of library references should be performed twice for both the .NET and J2EE projects. In the case of a .NET application we add a reference to a DLL; in the case of a J2EE application we add a reference to a JAR. Obviously this JAR library could be developed using native java source files or using Visual MainWin. Practically, if the ASP.NET application references a DLL assembly, the new J2EE application will have to reference the same library in JAR format. If the source files of this library are available, we can use the Visual MainWin compiler (in a separate project) to get the JAR library. Contrarily, if the source files are not available, we need require a JAR format of this library from the provider. To this intention, MainSoft signals the availability of the Infragistics controls for the J2EE platform. Unfortunately, Visual MailWin doesn't allow us to get a Jar library directly from a DLL assembly without using the source code.

    As a rule, a traditional ASP.NET project can reference only the resources involved in the compilation process: aspx pages and C# or VB source files. The other files (bitmap, CSS, client-side script, etc.) could be copied to IIS without being referenced in the ASP.NET project. Contrarily, a J2EE application is entirely stored in a single war file that holds the whole application. This means that we must reference all the resources before creating the war file. Besides, the "Deployment Packager" option (show in the following figure) allows us to produce a deployment file that includes the whole Run-Time components, including the Visual MainWin framework library.

    Debug and Execution

    The compilation process is very slow and, for the complexes projects, can require several minutes. Before activating debugging, Visual Studio deploys the application on Tomcat and then actives Internet Explorer. The debugging of a J2EE application has a similar behavior to that of a tradition ASP.NET debugger. The execution of these applications on Tomcat is equivalent to the execution of the applications written with native Java code. The ".aspx" extension of the Web pages is the only indication that the application is derived from a .NET solution.

    Database Access

    Visual MainWin maps the open and close statements of the Database Connection with the equivalent JDBC statements without requiring the change of the original ConnectionStrings. In this scenario, the application execution effects the physical open and close of the DB Connection corresponding to these JDBC statements without using the ConnectionPooling managed by the application server.

    The following figure shows the performance graph of a simple application that reads data from a database table and populates a dataset using a traditional ADO.NET ConnectionString:

    Alternatively, Visual MainWin allows you to use the JNDI DataSource defined on the Application Server. This option requires some modification of the configuration files; for more details see: http://dev.mainsoft.com/Default.aspx?tabid=32&src=ConfiguringForJndiDataSource.html. As a rule, if the application holds the DbConnectionString in a configuration file (such as Web.Config), to use JNDI DataSource we don't modify the source code; it is enough to modify these configuration files: web.config, web.xml, etc. The following figure shows the performance graph of the same application using a JNDI Database connection.

    The use of the DataSources JNDI allows a notable increase of the performances, while the SQL Profiler comfirms the use of a single DB connection during the execution of the whole test.

    Workaround

    Visual MainWin doesn't implement the namespaces OracleClient or ODBCClient; to access to an Oracle Database we need to use the classes of the namespace OleDb (that introduces evolved functionality) implemented in the System.Data.jar library.

    The official MainSoft documentation exposes other limitations (see: http://dev.mainsoft.com/Default.aspx?tabid=32&src=Limitations.html); some are mandatory, other limitations are due to inefficient java bytecode.

    We can use conditional compilation in order to implement different behaviours between the .NET and J2EE releases:

    #if JAVA
    ...// do something 
    #else
    ...// do otherwise 
    #endif
    

    The tests I have run have indicated that it is unlikely that you'll be able to port a real world application to Tomcat on the first try due to several problems. These problems could be tied to the limitations described above or other limitations imposed by the new system. For instance, Tomcat is case-sensitive while IIS is case-insensitive; therefore we need to verify the case of all URLs used by the application.

    Unfortunately, we may also run into other problems that are difficult to predict due to typical defects of the system. This situation shouldn't be a since it is part of the natural life cycle of every software product.

    Performance and Scalability

    The tests were run on a system that was not specifically configured for offering high performances. However these tests have verified the application scalability:

    • the increase of the number of connected clients doesn't have to decrease the server availability
    • the increase or the persistence of the client requests doesn't have to presents pauses or system blocks

    The tests were performed using Microsoft Application Center Test rel. 1.0.536 simulating a increasing number of client for 60 seconds.

    As we have already seen, the use of the JNDI DataSources guarantees better performance and has good scalability. The following tests perform a Web Application that reads the data from several tables, inserts the data into a DataSet and then exports it as an XML stream. The following figure show the performance graph of this application using a JNDI DB Connection.

    The execution on IIS of the .NET version of the same application allows better performance. This result doesn't really surprise us: it is known that the .NET applications are generally faster than Java applications. As a rule, the J2EE technology is normally used to port the application in situations where .NET technology is not available.

    Now we can ask: what is the performances comparison between a J2EE application developed with Visual MainWin and a similar application written with Java? To answer this question I've implemented the same application using the Java language. The following figure show the performance graph of this native Java application that underlines a slight increase in performance:

    Conclusion

    Visual MainWin is a very special product because it stands at the crossroad between two very popular technologies. Therefore it will probably have a meaningful evolution in the coming years. Nevertheless it is unlikely that Visual MainWin will be able to support the technological evolution of both the Java and .NET. platform in a timely fashion. Therefore, this product probably won't be used by developers that are interested in a single platform. Contrarily Visual MainWin is an essential tool for those who need the highest portability for their applications.

    About the Author

    Marco Nanni is an Italian developer with experience in Web technology used for implementing enterprise solutions. Marco can be contacted at: mnanni (at) lycos (dot) it

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Oct 6, 2005 - A Quick Look at Xamlon Web
    Have you ever wanted to deploy a WinForms application to the web or wished you could build fancy Flash-based user interfaces easily? If so, then Xamlon Web might just be the product for you. Xamlon Web allows you to create WinForms applications in C# or VB.NET and deploy them anywhere on the web using Macromedia Flash without any previous Flash experience.
    [Read This Article]  [Top]
    Jul 28, 2005 - N-Tier Web Applications using ASP.NET 2.0 and SQL Server 2005 - Part 2
    In the second part of his series on building N-tier web applications using ASP.NET 2.0 and SQL Server 2005, Thiru Thangarathinam covers the business logic and user interface layers. In the process, he also examines some new features in ASP.NET 2.0 that greatly simplify the development process.
    [Read This Article]  [Top]
    Jul 14, 2005 - An Innovative Technique for Creating Reusuable Page Templates in ASP.NET 1.x
    Code reusuability is one of the major goals of any good object-oriented programmer. While the ASP.NET framework has made code reusuability easier and more elegant than it was in classic ASP, one area where reusuability could be improved is at the UI level. This article outlines a technique that you can use in ASP.NET 1.x that allows every page in your web application to inherit not only the functionality of a base page, but its UI as well.
    [Read This Article]  [Top]
    Jun 23, 2005 - Monitoring SharePoint Usage through an ASP.NET Web Application
    In this article, Gayan Peiris looks at creating an ASP.NET web application that will display the usage details of a selected SharePoint site. Building such an application enables SharePoint administrators to gather all SharePoint usage data from a central location.
    [Read This Article]  [Top]
    May 12, 2005 - Retrieving SharePoint Site Information in an ASP.NET Web Application
    In this article, Gayan Peiris examines using the SharePoint Object Model to access SharePoint site information from an ASP.NET web application. It should be of particular interest to SharePoint administrators who can use the included code as a starting point for development of their own web-based SharePoint administration application.
    [Read This Article]  [Top]
    Dec 23, 2004 - Automated Deployment for Side By Side .NET Web Apps for Visual Studio .NET 2003
    In this article, David Every outlines a step-by-step account of how he solved the problems he encountered while implementing an auto-deployment process. He also describes how to create a stable process for automated remote .NET deployment featuring "side-by-side" capability.
    [Read This Article]  [Top]
    Sep 29, 2004 - Developing Web Parts with ICellConsumer Interface
    Most default SharePoint Server Web Parts can be connected across organizations. The third article in this series shows how to develop connectable Web Parts that consume information provided by other Web Parts.
    [Read This Article]  [Top]
    Aug 10, 2004 - Implementing and Promoting Daily Builds
    Automatic daily builds is a well known software engineering best practice. This article introduces a strategy for implementing and promoting daily builds and offers tips and tricks for preventing and fixing breaks.
    [Read This Article]  [Top]
    Jun 21, 2004 - Using Open Source .NET Tools for Sophisticated Builds
    Building an application can be more than pressing F5. With an increasing number of quality packages being released, developers for the .NET platform now have options to create a very sophisticated build process. Aaron Junod describes a sample build environment and shows how a number of tools can work together to make reliable, predictable, and value-added builds.
    [Read This Article]  [Top]
    Jun 24, 2003 - Programming for the Palm Part 1 - Creating the Palm Application
    The first part of this three part series walks through the process of creating a mobile blog application using a BASIC development environment for Palm OS devices called NS Basic. Subsequent articles will focus on synchronizing the data to the desktop using C# and creating an installer.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry

    internet.commediabistro.comJusttechjobs.comGraphics.com

    Search:

    WebMediaBrands Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs