A simple "Hello" example -- .NET Server & Java Client

Description:

Build a small 'hello world' console application:

Source:

\DemoJava\Hello_DotNetServer


Example

Step 1. Write the Java client:

a.) Remote interface (Hello\Greetings.java):

  ...
  public interface Greetings extends Remote  
  {
    String hello( String name) throws RemoteException;  
  }

b.) The Java main (Client.java):

Connect the name service:

  Context initialNamingContext = new InitialContext();  

Get an object reference to the remote object.
It is assumed that the remote object is known as 'HelloJavaServer' in the name service:

  Greetings oGreetings= (Greetings) initialNamingContext.lookup("HelloDotNetServer");  

c.) Compile the Java project:

    > mkdir classes
    > javac -classpath . -d classes Client.java
    > javac -classpath . -d classes Hello\Greetings.java
    > rmic -iiop -classpath .\classes -d classes Hello.Greetings  
    > cd classes
    > jar cvf ..\Client.jar .
    > cd ..

Step 2. Generate the IDL files

> BrewerCmd -cp Client.jar -g idl -v -d ..\IDL Hello.Greetings

Step 3. Generate .NET code form the IDL-File

> BrewerCmd -all -g cs -d ..\DotNetServer\Generated ..\IDL\Hello.idl  

Step 4. Write the .NET Server

a.) Create a console application.

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

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

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

  public class GreetingsImpl : Hello.GreetingsPOA
  {
    public GreetingsImpl()
    {
    }
    override public string hello(  string a_strTest  )
    {
      System.Console.WriteLine("Method executed: Greetings.hello( {0})", a_strTest);  
      return "Thanks for calling";
    }
  }

Create RuntimeConfiguration, set naming service URI and turn on log option. (refer User Guide for more RuntimeConfiguration options)
Use the RuntimeConfiguration to initialize an ORB object.

  RuntimeConfiguration rc = new RuntimeConfiguration();
  rc.SetNamingServiceInitialReference("corbaloc:iiop:1.2@localhost:10050/NameService");  
  rc.SetApplicationLog(OrbErrorLevel.ERRORS, "SrvLog.log", false);
  Ics.CORBA.ORB oOrb = Ics.CORBA._ORB.init(rc);

Publish the reference with the name service. Use the 'HelloDotNetServer' as the name by which the object is published:

  Ics.PortableServer.POA oRootPOA = Ics.PortableServer.POAHelper.narrow( oOrb.resolve_initial_references( "RootPOA" ));
  oRootPOA.the_POAManager.activate();
  Ics.CORBA.Object oObjRef = oRootPOA.servant_to_reference(  new GreetingsImpl() );
  Ics.CosNaming.NamingContext oNamingContext = Ics.CosNaming.NamingContextHelper.narrow( oOrb.resolve_initial_references("NameService") );  
  Ics.CosNaming.NameComponent[] arNameComp = new Ics.CosNaming.NameComponent[1];
  arNameComp[0].id = "HelloDotNetServer";
  oNamingContext.rebind(arNameComp, oObjRef);

Step 5. Run the example

a.) Start the sun name service on port 10050:

    > start orbd -ORBInitialPort 10050  

(could also use startNameService.bat located in the DemoJava directory to quick start the name service)

c.) Start the .NET Server.

b.) Start the Java Client by using JNDI CosNaming and work with a name service

running on 'localhost' at port '10050':

    > java -cp .;Client.jar -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:10050 Client  

(could also use buildClient.bat and startClient.bat located in the JavaServer directory to quick build and run the Java Client)