CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Wednesday, August 30, 2006

Enterprise Java Beans(EJB) from .NET (C# or VB.NET)

Getting your ASP.NET application to interact with your J2EE application server and invoke EJBs is as easy as invoking XML Web services.

Introduction

Today, many large organizations find themselves working with a mixture of .NET and J2EE™ development teams and deployment servers. To leverage the enterprise-class quality delivered by the J2EE application server, corporate business logic is often deployed on J2EE application servers as Enterprise JavaBeans™ (EJBs). On the other hand, to meet ever-changing business requirements, most developers prefer implementing the presentation logic in the highly productive environment of the Visual Studio .NET® development environment. The challenge arises when you need to connect the .NET presentation layer to the J2EE business logic.

Figure 1. StocksPortfolio application running on the JBoss application server.

Let's see how Visual MainWin® for J2EE helps you face this challenge and develop, from within Visual Studio .NET, an ASP.NET presentation layer that is written in C# or Visual Basic .NET® and invokes business logic that is implemented as EJBs. You will do this without having to code the daunting EJB APIs. With Visual MainWin for J2EE, both layers – the ASP.NET front-end and the EJB back-end – run as a pure J2EE application on your J2EE application server, with optimal performance and with unified, J2EE-based security.

To invoke EJBs from within Visual Studio .NET, you must have the Enterprise Edition of Visual MainWin for J2EE installed. You can download an evaluation copy from here.

Let’s go through an example

The Stocks Portfolio (StocksPortfolio) sample, which demonstrates how to create an application with an ASP.NET Web tier and a J2EE business tier, is installed and documented within Visual MainWin for J2EE.

Figure 2. Add EJB Reference.

This sample implements a simple ASP.NET Web page that users use to manage their stocks portfolio, and an ASP.NET Web service that provides fictitious stock quotes. The sample also uses a session EJB, which can be deployed on your J2EE application server to implement the logic of buying and selling stocks.


Adding the EJB to your .NET environment

Invoking an EJB from Visual Studio .NET is as simple as invoking a Web service. In your Solution Explorer, right-click on References and then choose Add EJB Reference, a new reference type available in Visual MainWin for J2EE projects only, which is similar to Web References in the standard Visual Studio .NET IDE (see Figure 2).


To add an EJB reference to your Visual MainWin for J2EE project, all you need is the Java™ Archive (JAR) file that implements the EJB or contains its home and remote interfaces. Visual MainWin queries the application server for all the EJBs deployed on it and displays the EJBs corresponding to your JAR definitions in the dialog. You simply need to select the specific EJB(s) you want to use (see Figure 3).


You can also consume EJBs deployed on a remote application server, as long as it is the same type as the local application server with which your project is associated. This can be a Windows®, Linux®, UNIX®, Mainframe or any other J2EE-enabled server.

Figure 3. Add EJB Reference dialog.

Figure 4. Add EJB Reference dialog, Advanced mode.

To consume an EJB deployed on a remote server, click Advanced to expand the dialog (see Figure 4).

Enter the JNDI URL to the remote J2EE application server and click Fetch From Server. Visual MainWin lists the EJB(s) that are deployed on the remote server and that correspond to your JAR file. The process is the same for local EJBs.


Select the EJB(s) you want to consume and click OK. A new EJB References folder is created inside your Solution Explorer browser, as shown in Figure 5. The folder contains server-based references for each EJB reference added, similar to the Web References node. In addition, a wrapper class is created to simplify your EJB invocation coding. The wrapper class is discussed further in the next section.

Continue with updated article

, , , , , , ,

Post a Comment