HelloCpp - A 'Hello' using Visual Basic with CORBA

Description:

Build a small 'hello world' console application:

Function:

The client calls a function provided by a remote server, with the following signature 'string hello(string)' and displays the result.

Goal:

Write the CORBA IDL, generate C# code from IDL, and write server & client application in Visual Basic accessing the generated C# code.

Source:

\Demo\HelloVB


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 -o Hello Hello.idl  

This creates a C# Shared DLL named Hello.dll.

Step 3. Write the Visual Basic Server

a.) Create a console application.

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

c.) Add a reference to the new DLL.

d.) Write an implementation for the IDL (within HelloSrv.vb):

        Public Class Greetings
            Inherits Hello.GreetingsPOA
            
            Sub New()
            End Sub
            
            Public Overrides Function Hello(ByVal strMyName As String) As String
                Console.WriteLine("Function 'Hello' Parameter '{0,20}'", strMyName)   
                Hello = "Greetings to " + strMyName
            End Function
            
        End Class  

e.) Write the server (HelloSrv.vb):

Initialize the CORBA ORB using RuntimeConfiguration:

    Dim rc As RuntimeConfiguration
    rc = New RuntimeConfiguration
    rc.SetApplicationLog(OrbErrorLevel.ERRORS, "SrvLog.log", False)  
    rc.SetORBEndpoint("localhost", 1357, 0)

    Dim orb As Ics.CORBA.ORB
    orb = Ics.CORBA._ORB.init(rc)

Retrieve the Object Adaptor (POA) from the ORB:

  Dim poa As Ics.PortableServer.POA
  poa = Ics.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA"))  

Activate the POA:

  poa.the_POAManager.activate()  

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

  Dim oGreetings As Greetings
  oGreetings = New Greetings()
  
  Dim obj As Ics.CORBA.Object
  obj = poa.servant_to_reference(oGreetings)   

Publish the CORBA object reference using a flat file:

  Dim strIORFile As String
  strIORFile = "c:\\hello.ior"

  Ics.CORBA._ORB.wrIORtoFile(strIORFile, obj)  

Finally, start the ORBs main event loop:

  orb.run();  

Step 4. Write the Visual Basic Client

a.) Create a console application.

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

c.) Add a reference to the new DLL.

d.) Write the client (HelloClt.vb):

Initialize the CORBA ORB using RuntimeConfiguration:

    Dim rc As RuntimeConfiguration
    rc = New RuntimeConfiguration
    rc.SetApplicationLog(OrbErrorLevel.ERRORS, "CltLog.log", False)

    Dim orb As Ics.CORBA.ORB
    orb = Ics.CORBA._ORB.init(rc)  

Retrieve the CORBA server object reference from the flat file:

  Dim strIORFile As String
  strIORFile = "file://c:\\hello.ior"

  Dim obj As Ics.CORBA.Object
  obj = orb.string_to_object(strIORFile)  

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

  Dim oGreetings As Hello.Greetings
  oGreetings = Hello.GreetingsHelper.narrow(obj)  

Finally, call the remote server object:

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

Step 5. Run the example

a.) Start the Server.

b.) Start the Client.