CORBA Connectivity: A Simple CORBA Application

We will demonstrate the use of J-Integra® Espresso with the help of a simple example. We create two console applications: a server and a client. The server provides functionality which the client will call using CORBA.

Step 1: The IDL File

Any CORBA-based design begins with the layout of the interfaces needed by the application. All interfaces and additional types are defined in an IDL file. In our 'hello' example we have one interface 'Greetings' with a single method 'hello'. The parameter is a string.

// hello.idl

module Example {
  interface Greetings {
    void hello( in string strName );
  };
};

The IDL source is stored in the file 'hello.idl'. In order to generate code, one has to call the IDL compiler IcsIdl2Cs.exe.

> IcsIdl2Cs.exe hello.idl

The IDL compiler creates a file 'hello.cs' containing stubs, skeletons, and several helper classes.

Step 2: The Server Code

It takes only a few steps to create the server part of the application:

  1. Create a new C# console application for the server using your preferred .NET IDE.
  2. Add the generated source file 'hello.cs' which contains CORBA stubs and skeletons.
  3. Add a reference to Jintegra.Espresso.dll, the J-Integra® Espresso ORB runtime located in the bin directory.
  4. Implement the server code.

One of the central tasks for writing the server code is the implementation of the interface 'Greetings'. The generated class 'GreetingsPOA', which serves as the base class for 'GreetingsImpl', provides a link between the object implementation and the object adapter. In the 'Main' of our server program we first initialize the ORB and the Portable Object Adapter (POA), register the servant, export the Interoperable Object Reference (IOR) and call the ORB's run() method which starts the main event loop waiting for external CORBA requests.

using System;
using Example;

namespace Server
{
  
  public class GreetingsImpl: GreetingsPOA {
    public override void hello(  string  strName ) {
      Console.WriteLine("Function 'Hello', Parameter '{0}'", strName);
    }
  }

  class Server {   
    static void Main(string[] args) {
      Ics.CORBA.ORB oOrb = Ics.CORBA._ORB.init( args, null);
      Ics.PortableServer.POA oRootPOA 
        = Ics.PortableServer.POAHelper.narrow(
            oOrb.resolve_initial_references( "RootPOA" ) );

       
      // activate POA
      oRootPOA.the_POAManager.activate();

      // implementation of the Greetings Interface
      GreetingsImpl oGreetings = new GreetingsImpl();
    
      // register servant with POA
      Greetings oIGreeting = oGreetings._this( oOrb );

      // write IOR-File
      Ics.CORBA._ORB.wrIORtoFile("c:\\hello.ior", oIGreeting );

      // workup Requests        
      oOrb.run();
    }
  }
  
}

Step 3: The Client Code

The client is created in a similar way:

  1. Create a new C# console application for the client using your preferred .NET IDE.
  2. Add the generated source file 'hello.cs' which contains CORBA stubs and skeletons.
  3. Add a reference to Jintegra.Espresso.dll, the J-Integra® Espresso ORB runtime located in the bin directory.
  4. Implement the client code.

The client reads the IOR from a file which the server created at startup. With the help of the IOR the client can connect to the server and call the function 'hello'.

using System;
using Example;

namespace Client {

  class Client {
    static void Main(string[] args) {
      Ics.CORBA.ORB oOrb = Ics.CORBA._ORB.init(args, null);
      Ics.CORBA.Object oGreetingsObj
        = oOrb.string_to_object("file://C:\\hello.ior");

      Greetings oIGreetings  = GreetingsHelper.narrow( oGreetingsObj  );
      oIGreetings.hello("Santa Claus");
    }
  }

}

Step 4: Running the Application

After starting the server and the client, the output on the server screen should contain the following line.

Function 'Hello', Parameter 'Santa Claus'.