Main page / Java Connectivity page

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: 
	MinCor\DemoJava\Callback

Mapping: 
	java.rmi.Remote  <--->  Middsol.CORBA.Object



Example 

The Java server:

    Interface     : Callback\ServerAdmin.java
    Implementation: Callback\ServerAdminImpl.java

    
    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;
    }
    


The .Net client:
 
    Implementation: ClientImpl.cs
    IDL-File      : Callback.idl
    Generated     : Callback.cs


    The implementation of the .Net callback object within ClientImpl.cs
    (Callback.GreetingsPOA is generated class):
          
          
    public class GreetingsImpl: Callback.GreetingsPOA
    {
        public string m_strMessage;
         
        public GreetingsImpl()
        {
        }

        override public string hello(  string a_strMessage )
        { 
            m_strMessage = "Method executed: Greetings.hello( "+ a_strMessage + ")" ;
            return "Thanks for callback";
        }
    }
	

    Instantiate the .Net callback object and call of the remote java interface:
          
    Callback.Greetings oGreetings = new GreetingsImpl()._this();
    oServerAdmin.regCallBack( "Middsol", oGreetings);