Callback - Callbacks from Java to .NET

Description:

The Java server exports a function which has a 'java.rmi.Remote' object as parameter.
When a client calls this server function the server uses the received remote object to execute a callback to the client.

          Client(.NET)            Server (Java)
          -----------------------------------------          
             call        ---->          |
               |                        |
               |         <----       callback
               |         ---->          |
               |                        |
               |         <----          |

Source:

\DemoJava\Callback

Mapping:

java.rmi.Remote <---> Ics.CORBA.Object


Example

Step 1. Write the Java server:

  public class ServerAdminImpl extends PortableRemoteObject implements ServerAdmin
  {
  ...
    public void regCallBack(String name, Greetings oCallBack) throws RemoteException 
    {  
      oCallBack.hello("Hi " + name));
    }
  }

Callback interface: Callback\Greetings.java

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

Step 2. Write the .NET client:

The implementation of the .NET callback object within main.cs (Callback.GreetingsPOA is generated class):

  public class GreetingsImpl : Callback.GreetingsPOA 
  {  
    override public string hello(string a_strTest) 
    {
      System.Console.WriteLine("{0}", a_strTest);
      return "Thanks for callback";
    }
  }

Instantiate the .NET callback object and call of the remote java interface:

  Callback.Greetings oGreetings = new GreetingsImpl()._this();  
  oServerAdmin.regCallBack("Ics", oGreetings);

Step 3. 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)

b.) Start the java server by using JNDI CosNaming and work with a name service running on 'localhost' at port '10050':

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

(could also use buildServer.bat and startServer.bat located in the JavaServer directory to quick build and run the Java Server)

c.) Start the .NET Client.