Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Connecting CORBA to .NET : Page 2

In this article, you'll see how to build a CORBA server and connect it to C# clients using Borland's Janeva as "glue".


advertisement

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 <corba.h>
   #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 4 shows the running application.

Figure 4. The Running CORBA Server: Here's a screenshot of the completed CORBA server.

Note that the code checks the duration of the meeting. If the meeting lasts longer than one hour (60 minutes), the code throws a CORBA exeception with the message "I don't like long meetings." Obviously, this exception exists purely to demonstrate how to use CORBA exceptions, and to show how the C# client can receive and respond to errors.

Before you can run the CORBA Server, you must make sure the VisiBroker Smart Agent is also running.

Author's Note: See http://www.drbob42.com/examines/examin10.htm for an implementation of the CORBA server and a client that can connect to it using Delphi 5 (from 2000).



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap