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:
> MCidl2cs.exe Hello.idl
Step 2. Write the C# Server
a.) Create a mobile application.
b.) Add a reference to 'MinCor\bin\MinCorCF.DLL'
c.) Add the generated file: Hello.cs.
d.) Write an implementation for the IDL (within ServerImpl.cs):
public class GreetingsImpl: Example.GreetingsPOA
{
private ServerImpl m_oServer;
public GreetingsImpl( ServerImpl a_oServer)
{
m_oServer = a_oServer;
}
override public string hello( string a_strName )
{
m_oServer.theFrm.writeLog("Method executed:");
m_oServer.theFrm.writeLog(" GreetingsImpl:hello");
m_oServer.theFrm.writeLog(" Parameter:" + a_strName);
return "Hallo " + a_strName ;
}
}
e.) Write the server (ServerImpl.cs):
Initialize the CORBA ORB:
Middsol.CORBA.ORB oOrb = Middsol.CORBA._ORB.init( strOpt, null);
Retrieve the Object Adaptor (POA) from the ORB:
Middsol.PortableServer.POA oRootPOA
= Middsol.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();
Middsol.CORBA.Object obj = oRootPOA.servant_to_reference( oGreetings);
Publish the CORBA object reference using a flat file:
Middsol.CORBA._ORB.wrIORtoFile( ".\\HelloSrv.ior", obj );
f.) Implement a hosting frame (HelloSrv.cs).
Step 3. Write the C# Client
a.) Create a mobile application.
b.) Add a reference to 'MinCor\bin\MinCorCF.DLL'
c.) Add the generated file: Hello.cs.
d.) Write the client (ClientImpl.cs):
Initialize the CORBA ORB:
Middsol.CORBA.ORB oOrb = Middsol.CORBA._ORB.init( strOpt, null);
Retrieve the CORBA server object reference from the flat file:
Middsol.CORBA.Object obj = oOrb.string_to_object( "file://.\\HelloSrv.ior" );
Downcast ("narrow") the CORBA object to the 'Greetings' interface:
Hello.Greetings oGreetings = Hello.GreetingsHelper.narrow( obj );
Finally, publish the remote server object as an attribute:
public Example.Greetings Greetings
{
get{ return m_oGreetings;}
}
e.) Implement a hosting frame (HelloClt.cs):
Call the remote server object:
private void btSend_Click(object sender, System.EventArgs e)
{
if( m_oClientImpl != null)
{
txtReturn.Text = m_oClientImpl.Greetings.hello( txtTextLine.Text);
}
}
Step 4. Run the example
a.) Copy Server & Client to a common directory of the target machine.
b.) Start the Server.
c.) Start the Client.