Connecting CORBA to .NET

ORBA, the acronym for Common Object Request Broker Architecture, is a widely used communications model for building distributed (multi-tier) applications that connect both cross-platform and cross-language clients to server-based services. Like J2EE, it’s not easy to connect CORBA to the .NET world, where ASP.NET Web services and .NET Remoting are the generic ways to build distributed applications. Making that connection requires a way to describe .NET objects as CORBA objects so that J2EE can interact with them, and a way to describe CORBA objects as .NET objects, so that managed .NET code can interact with them. In other words, you need some mediating code that can translate objects and method calls from CORBA’s representation to the .NET framework’s representation. Borland’s Janeva does exactly that: It simplifies the process of making that translation to connecting CORBA or J2EE objects to the .NET world.

Getting Started
To start, you need a CORBA server. Although some readers will have a server available and running, many won’t, so the first part of this article shows you how to create a simple CORBA server in C++ that you can use for practice and testing. It’s important to understand that the CORBA server could just as well be written using Java, Delphi, or any other language. The second part shows you how to connect to that server using Janeva.

The sample server that accompanies this article was built with Borland C++Builder 6 Enterprise. If you don’t have access to Borland C++Builder, you can use the compiled sample server application in the downloadable code for this article. The server is based on an existing application that maintains a personal agenda with appointments, used to schedule meetings electronically. The scheduling implementation details aren’t important for this article; it’s more important to focus on how to build and distribute the CORBA server interface specification that you’ll use at the client to experiment with Janeva’s connectivity.

Build a CORBA Server
To build the CORBA server, start C++Builder, click the File | New menu, select Other and go to the Multitier tab of the Object Repository (see Figure 1).

Figure 1. C++Builder Object Repository: The Object Repository contains a list of the items available
Figure 2. CORBA Server Wizard: You use this wizard to specify project options for a new CORBA server project.

A number of icons appear in the dialog related to CORBA. To start a new CORBA server project from scratch, double-click on the CORBA Server icon, which will display the CORBA Server Wizard so you can specify the options for the new project (see Figure 2).

You can choose to create a Console Application (with or without using Borland’s Visual Component Library) or a Windows Application. For this project, select the Windows Application option, because it’s convenient to have the server display some visual (debug) information during development.

A CORBA server can contain one or more CORBA objects. The interface specification for these CORBA objects are usually stored in IDL (Interface Definition Language) files. When you start a new CORBA server project, you can either select from among existing IDL files, or start with an empty IDL file and add your own CORBA object definitions. The sample project uses the simple IDL file shown below.

   module DiarySrv   {     struct DateTime {       long Date; // example: 20030929       long Time; // example: 1200     };        interface ICorbaDiaryServer     {       exception MeetingImpossible       {         string Reason;       };          void Meeting(in wstring Names,                    in DateTime DayTime,                    in long Duration)         raises (MeetingImpossible);     };   };   

When you click the OK button in the CORBA Server Wizard, C++Builder generates the new project. Save the form as MainForm.cpp and the main project file as BCB6CorbaServer.bpr. The IDE adds the DiarySrv.idl file to the project. When you compile the project, C++Builder runs the idl2cpp tool, which generates four additional files based on the IDL definition, namely: DiarySrv_c.cpp and DiarySrv_c.hh (for the stub classes) as well as DiarySrv_s.cpp and DiarySrv_s.hh (for the skeleton classes).

Figure 3. CORBA Object Implementation Wizard: You use this Wizard to specify the IDL file, select interface names, the delegation model, and other properties.

CORBA Object Implementation
Apart from the skeleton and the stub, you need an actual implementation of the DiarySrv CORBA object. For that you can use the CORBA Object Implementation wizard (see Figure 1 for the icon in the Object Repository). Click File | NewOther, go to the Multitier tab, and double-click on the CORBA Object Implementation icon, which will display the dialog shown in Figure 3.

For each IDL file, you can select all interface names, and the wizard will suggest the unit name, class name, etc. You can then specify whether you want to use the delegation model, use a data module, and whether you want to create the object instance inside WinMain (an alternative is to create it inside your main form, for example).

When you click on OK, the IDE adds two new files to your project: ICorbaDiaryServer.cpp, and ICorbaDiaryServer.h. This is the place to write the implementation of the actual CORBA server object, which is simplistic for this sample server.

   #pragma hdrstop      #include    #include "ICorbaDiaryServerServer.h"      #include "MainForm.h"      //----------------------------------------------------      #pragma package(smart_init)         ICorbaDiaryServerImpl::ICorbaDiaryServerImpl(      const char *object_name):      _sk_DiarySrv::_sk_ICorbaDiaryServer(object_name)   {     if (Form1)        Form1->Caption =         "ICorbaDiaryServer up and running...";   }      void ICorbaDiaryServerImpl::Meeting(      const CORBA::WChar* _Names,      const DiarySrv::DateTime& _DayTime, CORBA::Long       _Duration)   {     if (Form1)       Form1->Memo1->Lines->Add(          "Meeting with " + AnsiString(_Names));     if (_Duration > 60)        throw        DiarySrv::ICorbaDiaryServer::MeetingImpossible(        "I don't like long meetings...");   }

Figure 5. C#Builder New C# Application Wizard: You use this wizard to specify the name and location of the new project.

Build a CORBA Client
I’ve used C#Builder to create this .NET CORBA client in C#, but the concepts work equally well with any .NET language. Start C#Builder Enterprise or Architect, and create a new C# application. In the New Application dialog you can specify the name as well as the location of the new project (see Figure 5).

Borland Janeva 1.0
Borland Janeva delivers seamless, high-performance interoperability between Microsoft .NET Framework applications and J2EE/CORBA server objects. The Enterprise and Architect editions of C#Builder Enterprise both include Janeva, but you can also download Janeva separately from the Borland Web site (and use it with other .NET development environments—see the end of this article for more information).

Figure 6. Add CORBA Reference: Janeva adds two items to the Add References menu, letting you select J2EE or CORBA references as well as standard file or Web references.

After the free registration, you get a development license from Borland that’s suitable for testing purposes; however, you must purchase a deployment license before you can deploy .NET clients you create (see the Janeva documentation itself for more details).

After installing Janeva, you can right-click on the main project file inside the Project Manager in C#Builder, and add a J2EE or CORBA Reference (see Figure 6). Without Janeva, you can add only regular references (normal files) or Web references (Web services) to the project.

Because the example project is a CORBA server, select the Add CORBA Reference item, which then displays a dialog where you can specify the IDL file that holds the CORBA server definition—in this case DiarySrv.idl (see Figure 7).

CORBA Server applications publish their “interface” definition using these Interface Definition Language (IDL) files. Development environments supporting CORBA client applications usually offer support to convert the IDL to native computer languages such as C++ or Java. For a .NET client, however, some process must convert the IDL to a .NET language, such as VB.NET or C#. This IDL-to-C# (IDL2CS) conversion is a welcome Borland Janeva feature.

Calling the CORBA Server
After configuring the client application, you can use a button to create an instance of the CORBA DiarySrv object and call the Meeting method as shown in the following button1_Click method.

   private void button1_Click(object sender,       System.EventArgs e)   {      try      {          MyCorbaDiaryServer =            ICorbaDiaryServerHelper.Bind(            "ICorbaDiaryServerObject");            DiarySrv.DateTime MyDateTime = new             DiarySrv.DateTime();         MyDateTime.Date =             Convert.ToInt32(textBox2.Text);         MyDateTime.Time =             Convert.ToInt32(textBox3.Text);         MyCorbaDiaryServer.Meeting(textBox1.Text,            MyDateTime, Convert.ToInt32(textBox4.Text));      }      catch          (DiarySrv.ICorbaDiaryServerNS.MeetingImpossible             ex)         {           MessageBox.Show(ex.Reason, "CORBA Exception");         }         catch (Exception ex)         {           MessageBox.Show(ex.Message, "Error");         }             }

See Listing 1 for the full Windows Form class code.

First, you have to call the Bind method, passing the exact name that was specified by the CORBA Server application to create the CORBA Diary Server object (in this case, that code was generated by C++Builder, and is “ICorbaDiaryServerObject”—see the downloadable C++ source files for details).

After binding the CORBA Server object, you can call the Meeting method. But not without retrieving the date and time and construction the special DiarySrv.DateTime object (the custom type defined in the IDL file and implemented by the CORBA server).

Figure 9. C#Builder CORBA Client: The figure shows the main window for the completed CORBA client running.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a