Hello - Getting started
Description:
Build a small 'hello world' console application:
-
Server written in .NET C#
-
Client written in .NET C#
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.
Source:
\Demo\Hello
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
HelloSrv.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 (HelloSrv.cs):
Initialize the CORBA ORB:
RuntimeConfiguration rc = new RuntimeConfiguration();
rc.SetApplicationLog(OrbErrorLevel.ERRORS, "SrvLog.log", false);
Ics.CORBA.ORB 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();
|
Instantiate the implementation of the IDL and generate a CORBA object reference
from the implementation object:
GreetingsImpl oGreetings = new GreetingsImpl();
Ics.CORBA.Object obj = oRootPOA.servant_to_reference( oGreetings);
|
Publish the CORBA object reference using a flat file:
Ics.CORBA._ORB.wrIORtoFile( "c:\\hello.ior", obj );
|
Finally, start the ORBs main event loop:
Step 3. Write the C# Client
a.) Create a console application.
b.) Add a reference to '[install dir]\bin\Jintegra.Espresso.dll'
c.) Add the generated file: Hello.cs.
d.) Write the client (HelloClt.cs):
Initialize the CORBA ORB:
RuntimeConfiguration rc = new RuntimeConfiguration();
rc.SetApplicationLog(OrbErrorLevel.ERRORS, "CltLog.txt", false);
Ics.CORBA.ORB oOrb = Ics.CORBA._ORB.init(rc);
|
Retrieve the CORBA server object reference from the flat file:
Ics.CORBA.Object obj = oOrb.string_to_object( "file://c:\\hello.ior" );
|
Downcast ("narrow") the CORBA object to the 'Greetings' interface:
Hello.Greetings oGreetings = Hello.GreetingsHelper.narrow( obj );
|
Finally, call the remote server object:
System.Console.WriteLine("{0}", oGreetings.hello( "Santa Claus" ));
|
Step 4. Run the example
a.) Start the Server.
b.) Start the Client.