EJBs for Everyone: Consume EJBs in .NET Using C# and a Web Service

Getting your apps ready to interact with a J2EE application server is a daunting task for the average VB.NET or C# developer, but Visual MainWin uses Web services to simplify the process. Find out how and learn to write and consume EJBs using C# and a .NET Server.

by Laurence Moroney

Apr 28, 2004

Page 1 of 3

he complexity involved in building enterprise-class apps is, unfortunately, beyond the skill-set of your average developer. It requires the consideration of a lot more than your actual application logic. The framework on which your application resides needs to handle high traffic, availability, and performanceall before you even write the specifics of your application! Done correctly, the framework takes care of the broad requirements of performance and scalability, leaving your developers free to write applications that are concerned only with their application-specific logic.

Architects generally face a fork in the road in the planning stages when designing an enterprise system. Should you build all of it yourselves? Going down to the level of threading models, messaging queues, object pools, and database connection pools? Or should you use an off-the-shelf enterprise application framework? This is where the J2EE spec, and more importantly the application server that implements this spec, comes in handy. If you choose to use an application server such as WebSphere, Weblogic, or JBoss, the infrastructure is already built for you. More importantly, it is tested and proven in many environments. In many cases, this is clearly a better option than trying to grow your own and test, deploy, and maintain it.

It seems like a no-brainer. Except that if you choose to use a pre-existing infrastucture, your apps need to be able to work with it.

EJBs to the Rescue
If your critical business logic resides in a technology like EJBs, your app will be infrastructure-ready. Once again, this not an easy task. Most companies have a large pool of Visual Basic, Java, or C# developers who are simply not up to this challenge. But Visual MainWin changes this, allowing you, the Visual Basic, Java, or C# developer to build an application (using C# or VB.NET) you can deploy to a J2EE application server.

Writing EJBs is but one part of this taskyou also have to consume them. Of course, consuming them can be just as difficult to the uninitiated. A well-designed application will have your EJBs in a business tier, which hopefully should not change too frequently. A high-level view of a typical architecture would look something like Figure 1.

An Enterprise Information System (EIS) may be scattered across many databases or other services, which are integrated using an abstraction layer termed the integration tier. The business tier takes this data and adds value to it through business logic. For example, an EIS may contain a real-time data source indicating the price of a stock, and another less-frequently updated data source containing the last posted earnings for a company. An EJB, residing in the business tier then calculates the common P/E (Price over Earnings) analytic. The presentation tier consumes this EJB in a given session and renders the results to the user.

In many cases, the rate of change of an application decreases the further you move away from the user. For example, in the above case P/E is always P/E and the EIS does not frequently change. As clients use your application, requirements change, and as such there is the need for changes such as in the presentation of the application or the addition of new features or integration points.

All too often, enterprises get stuck here. They discover the productivity benefits of using Visual Studio.NET and want to use it. However, plugging .NET into EJBs is not an easy task. They can bring in expensive J2EE experts to wrap the EJBs as Web services for .NET to consume and hope not to hit interoperability errors. Or they can throw away the EJBs and start again, building from the ground up using Microsoft tools and services.

Neither option is particularly attractive, and Mainsoft have brought a new option to the table with the introduction of Visual MainWin. The application is reviewed here, and an article in how to develop a simple Web service is posted here. The rest of this article will step you through creating a new presentation layer application as a Microsoft Web Forms application that consumes an EJB.

Editor's Note: Laurence Moroney is currently the Director of Product Evangelism at Mainsoft; however, he wrote this article for DevX before joining Mainsoft.