Contact us | Links | |||||||||||||||||||||
|
Accessing a RMI/IIOP-based CORBA object with .NET remotingIn this tutorial a .NET remoting client calls a method on a RMI/IIOP-based CORBA object: an adder. This RMI/IIOP adder provides a method to add two double summands. This tutorial consists of the following three steps:
Implementing the RMI/IIOP server
The Adder interface specifies the interface of the remote adder object: package Tutorial.GettingStarted; import java.rmi.Remote; import java.rmi.RemoteException; public interface Adder extends Remote { public double add(double arg1, double arg2) throws RemoteException; } The AdderImpl class implements the adder functionality: package Tutorial.GettingStarted; import java.rmi.Remote; import java.rmi.RemoteException; import javax.rmi.PortableRemoteObject; public class AdderImpl extends PortableRemoteObject implements Adder { public AdderImpl() throws java.rmi.RemoteException { super(); // invoke rmi linking and remote object initialization } public double add(double arg1, double arg2) throws RemoteException { return arg1 + arg2; } }
Every remotable RMI/IIOP object must implement an interface extending The AdderServer class creates an adder object and publishes it with a CORBA naming service: import javax.naming.InitialContext; import javax.naming.Context; import javax.rmi.PortableRemoteObject; import Tutorial.GettingStarted.Adder; import Tutorial.GettingStarted.AdderImpl; public class AdderServer { public static void main(String[] args) { try { // Instantiate the service AdderImpl adder = new AdderImpl(); // publish the reference with the naming service: Context initialNamingContext = new InitialContext(); initialNamingContext.rebind("adder", adder); System.out.println("Server Ready..."); } catch (Exception e) { System.out.println("Trouble: " + e); e.printStackTrace(); } } } The files can be found here: Compiling
Implementing the .NET Remoting Client Creating IDL for java types module Tutorial { module GettingStarted { interface Adder { double add( in double arg0, in double arg1 ); }; }; }; Mapping IDL to CLS using Ch.Elca.Iiop.Idl; namespace Tutorial.GettingStarted { [RepositoryIDAttribute("RMI:Tutorial.GettingStarted.Adder:0000000000000000")] [InterfaceTypeAttribute(IdlTypeInterface.ConcreteInterface)] public interface Adder : IIdlEntity { double add(double sum1, double sum2); } }
The predefined CORBA types are provided by IIOP.NET in the file IDLToCLSCompiler\IDL\orb.idl. Copy this file into your
java source directory JAVA_SOURCES_DIRECTORY.
Client code using System; using System.Runtime.Remoting.Channels; using Ch.Elca.Iiop; using Ch.Elca.Iiop.Services; using omg.org.CosNaming; namespace Tutorial.GettingStarted { public class NClient { [STAThread] public static void Main(string[] args) { try { string nameServiceHost = "localhost"; int nameServicePort = 1050; double sum1 = Double.Parse(Console.ReadLine()); double sum2 = Double.Parse(Console.ReadLine()); // register the channel IiopClientChannel channel = new IiopClientChannel(); ChannelServices.RegisterChannel(channel); // access COS nameing service CorbaInit init = CorbaInit.GetInit(); NamingContext nameService = init.GetNameService(nameServiceHost, nameServicePort); NameComponent[] name = new NameComponent[] { new NameComponent("adder", "") }; // get the reference to the adder Adder adder = (Adder)nameService.resolve(name); // call add double result = adder.add(sum1, sum2); Console.WriteLine("result: " + result); } catch (Exception e) { Console.WriteLine("exception: " + e); } } } }
A client must register the IIOP.NET channel with the .NET remoting framework before it can access CORBA objects.
After the channel registration, a reference to the CORBA nameing service, knowing the adder object, is retrieved.
Afterwards the client looks up the adder at the name service. Finally it uses the adder to add sum1 and sum2.
Compiling
Running the Demo
The client is afterwards started with the follwoing command line:
|
About this projectThis project is maintained by Elca Informatique SA and was developed in collaboration with the Programming Languages and Runtime Systems Research Group of the ETH-Zurich as part of Dominic Ullmann's diploma thesis. IIOP.NET Use CasesRead the IIOP.NET success stories. News
|
|||||||||||||||||||
© 2003-2004 ELCA All Rights Reserved |