Hello - A 'Hello' using the CORBA Naming Service

Description:

Build a small 'hello world' console application:

Function:

The server publishes its CORBA object reference within a CORBA Naming Service.
The client retrieves this reference from the CORBA Naming Service, calls a function with the signature 'string hello(string)' and displays the result.

Goal:

Write server & client application, using the standard CORBA Naming Service interface for publishing and retrieval.

Source:

\Demo\HelloNS


Example

Step 1. The CORBA IDL

a.) Write the IDL for the remote server (Hello.idl):

        module Hello
        {
            interface Greetings
            {
                string hello( in string a_strName);
            };
        };

b.) Compile the IDL file:

  > BrewerCmd.exe -g cs Hello.idl  

Step 2. Write the C# Server

a.) Create a console application.

b.) Add a reference to '$ESPRESSO_INSTALL_DIR$\bin\Jintegra.Espresso.dll'

c.) Add the generated file: Hello.cs.

d.) Write an implementation for the IDL (within HelloNsSrv.cs):

        public class GreetingsImpl: Hello.GreetingsPOA
        {
            public override string hello( string a_strName )
            {
               System.Console.WriteLine("\nFunction 'Hello', Parameter '{0}'\n", a_strName);  
               return "Greetings to " + a_strName;
            }
        }

e.) Write the server (HelloNsSrv.cs):

Initialize the CORBA ORB:

  RuntimeConfiguration rc = new RuntimeConfiguration();
  rc.SetApplicationLog(OrbErrorLevel.ERRORS, "SrvLog.log", false);     
  m_oOrb = Ics.CORBA._ORB.init(rc);			

Retrieve the Object Adaptor (POA) from the ORB:

  Ics.PortableServer.POA oRootPOA
    = Ics.PortableServer.POAHelper.narrow(
      oOrb.resolve_initial_references( "RootPOA" ));   

Activate the POA:

  oRootPOA.the_POAManager.activate();  

Retrieve the CORBA Naming Service from the ORB and downcast ("narrow") it to a 'NamingContext' interface:

  Ics.CORBA.Object oObjNsRef = oOrb.resolve_initial_references( "NameService" );
  Ics.CosNaming.NamingContext oNamingContext = Ics.CosNaming.NamingContextHelper.narrow( oObjNsRef );  

Instantiate the implementation of the IDL and generate a CORBA object reference from the implementation object:

  GreetingsImpl oGreetings = new GreetingsImpl();
  Ics.CORBA.Object oObjRef = oRootPOA.servant_to_reference( oGreetings);  

Create a Name for the CORBA object reference:

  Ics.CosNaming.NameComponent[] arNameComp = new Ics.CosNaming.NameComponent[1];  
        
  arNameComp[0].id = "Hello";
  arNameComp[0].kind = ""; 

Publish the CORBA object reference using the CORBA Naming Service:

  oNamingContext.rebind(arNameComp, oObjRef);  

Finally, start the ORBs main event loop:

  oOrb.run();  

Step 3. Write the C# Client

a.) Create a console application.

b.) Add a reference to '$ESPRESSO_INSTALL_DIR$\bin\Jintegra.Espresso.dll'

c.) Add the generated file: Hello.cs.

d.) Write the client (HelloNsClt.cs):

Initialize the CORBA ORB:

  RuntimeConfiguration rc = new RuntimeConfiguration();
  rc.SetApplicationLog(OrbErrorLevel.ERRORS, "CltLog.log", false);    
  m_oOrb = Ics.CORBA._ORB.init(rc); 

Retrieve the CORBA Naming Service from the ORB and downcast ("narrow") it to a 'NamingContext' interface:

  Ics.CORBA.Object oObjRefNs = oOrb.resolve_initial_references("NameService");
  Ics.CosNaming.NamingContext nc = Ics.CosNaming.NamingContextHelper.narrow( oObjNsRef );  

Create the Name for the CORBA object reference to retrieve:

  Ics.CosNaming.NameComponent[] arNameComp = new Ics.CosNaming.NameComponent[1];  
        
  arNameComp[0].id = "Hello";
  arNameComp[0].kind = "";  

Retrieve the CORBA server object reference from the CORBA Naming Service:

  Ics.CORBA.Object oHelloRef = nc.resolve( arNameComp);  

Downcast ("narrow") the CORBA object to the 'Greetings' interface:

  Hello.Greetings oGreetings  = Hello.GreetingsHelper.narrow( oHelloRef );  

Finally, call the remote server object:

  Console.WriteLine("\nCall Hello '{0}' returned '{1}'", "Santa Claus",  oGreetings.hello("Santa Claus"));  

Step 4. Run the example

a.) Start the CORBA Naming Service:

  > IcsNs.exe  

b.) Start the Server.

c.) Start the Client.