Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presentation 24 Ultra Simple.NET Remoting to CORBA bridge.

Similar presentations


Presentation on theme: "Presentation 24 Ultra Simple.NET Remoting to CORBA bridge."— Presentation transcript:

1 Presentation 24 Ultra Simple.NET Remoting to CORBA bridge

2 Ingeniørhøjskolen i Århus Slide 2 af 8 Outline This very simple sample will exemplify how to make a simple HelloWorld.NET Remoting server bridge to CORBA A real bridge will most often be generic, and translate on-the-fly with reflection mechanism’s using e.g. the Dynamic Invocation Interface Such bridges might be supplied by the vendor Here we will only make a “static” bridge

3 Ingeniørhøjskolen i Århus Slide 3 af 8 Making the HelloWorld application Using Microsoft Visual Studio.NET Only Remoting Client and Server Make the CORBA server yourself (or use Middcors “Hello” tutorial, which will fit perfectly for this) Server: –IHelloWorld.cs interface –HelloWorld.cs class implementation We place the bridging code in the sayHello method-call –Use Hello.idl to generate Hello.cs (Hello namespace) –Server.cs class implementation for boot-strapping –Add Reference to assembly System.Runtime.Remoting Add Reference to MiddCor.dll (for CORBA) Client (same as pure.NET Remoting example) –Must add IHelloWorld.cs –Client.cs class implementation –Add Reference to assembly System.Runtime.Remoting

4 Ingeniørhøjskolen i Århus Slide 4 af 8 The IHelloWorld interface using System; namespace RemotingHelloServer { // IHelloWorld is the interface for the HelloWorld server class. // It is the interface that is shared across the Internet public interface IHelloWorld { string sayHello(string name); } using System; namespace RemotingHelloServer { // IHelloWorld is the interface for the HelloWorld server class. // It is the interface that is shared across the Internet public interface IHelloWorld { string sayHello(string name); } The “IDL” of.NET Remoting – used between the Remoting server and client NOTHING NEW – same as Remoting example

5 Ingeniørhøjskolen i Århus Slide 5 af 8 Server code – Console bootstrapping using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; namespace RemotingHelloServer { public class Server { [STAThread] static void Main(string[] args) { //Create a TCP channel TcpChannel theChannel = new TcpChannel(8085) /* Register the channel so that clients can * connect to the server */ ChannelServices.RegisterChannel(theChannel); //Register the service on the channel RemotingConfiguration.ApplicationName = "HelloWorld App"; RemotingConfiguration.RegisterWellKnownServiceType( typeof(HelloWorld), "HelloWorld App", WellKnownObjectMode.SingleCall); /*Start the server and keep it running so that clients * can connect to it. May be aborted by keypress */ System.Console.WriteLine("Press Enter to end this server process"); System.Console.Read(); } } } using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; namespace RemotingHelloServer { public class Server { [STAThread] static void Main(string[] args) { //Create a TCP channel TcpChannel theChannel = new TcpChannel(8085) /* Register the channel so that clients can * connect to the server */ ChannelServices.RegisterChannel(theChannel); //Register the service on the channel RemotingConfiguration.ApplicationName = "HelloWorld App"; RemotingConfiguration.RegisterWellKnownServiceType( typeof(HelloWorld), "HelloWorld App", WellKnownObjectMode.SingleCall); /*Start the server and keep it running so that clients * can connect to it. May be aborted by keypress */ System.Console.WriteLine("Press Enter to end this server process"); System.Console.Read(); } } } Register the channel on port 8085 Register the channel on port 8085 Register the object Register the object Like in Java RMI (& CORBA) – we need some bootstrapping code – a server process This may become a Windows NT service or a simple application, e.g. a console or Windows Form application NOTHING NEW – same as Remoting example

6 Ingeniørhøjskolen i Århus Slide 6 af 8 Client code – Console bootstrapping … include all the Remoting stuff namespace RemotingHelloClient { public class Client { [STAThread] static void Main(string[] args) { TcpChannel theChannel = new TcpChannel(); ChannelServices.RegisterChannel(theChannel); /* Activate the server object. Activation will bring * the server object to life, and create a proxy * stub class of the HelloWorld. In fact, as this is a * server-activated application, the call to the * server is NOT performed now, but instead waits until the * first request. It is thus the server who performs the * activation. This is the "Lazy-activation pattern" known * from e.g. CORBA */ IHelloWorld helloWorld = (IHelloWorld) Activator.GetObject( typeof(RemotingHelloServer.IHelloWorld), "tcp://localhost:8085/HelloWorld App"); System.Console.WriteLine("Please enter your name and press Enter"); string name = System.Console.ReadLine(); //Make the call string greeting = helloWorld.sayHello(name); System.Console.WriteLine("We recieved from server: "+greeting); System.Console.WriteLine("Press Enter to end"); System.Console.Read(); } … include all the Remoting stuff namespace RemotingHelloClient { public class Client { [STAThread] static void Main(string[] args) { TcpChannel theChannel = new TcpChannel(); ChannelServices.RegisterChannel(theChannel); /* Activate the server object. Activation will bring * the server object to life, and create a proxy * stub class of the HelloWorld. In fact, as this is a * server-activated application, the call to the * server is NOT performed now, but instead waits until the * first request. It is thus the server who performs the * activation. This is the "Lazy-activation pattern" known * from e.g. CORBA */ IHelloWorld helloWorld = (IHelloWorld) Activator.GetObject( typeof(RemotingHelloServer.IHelloWorld), "tcp://localhost:8085/HelloWorld App"); System.Console.WriteLine("Please enter your name and press Enter"); string name = System.Console.ReadLine(); //Make the call string greeting = helloWorld.sayHello(name); System.Console.WriteLine("We recieved from server: "+greeting); System.Console.WriteLine("Press Enter to end"); System.Console.Read(); } Create Proxy Call via Proxy object Optional (may be done implicitly) NOTHING NEW – same as Remoting example

7 Ingeniørhøjskolen i Århus Slide 7 af 8 HelloWorld Implementation code using System; using System.Runtime.Remoting; using Middsol; using Hello; namespace RemotingHelloServer { // HelloWorld is a server object that is available // "by-reference". It contains a constructor and a the // "sayHello" method taking a string parameter "name" public class HelloWorld : MarshalByRefObject, IHelloWorld { public string sayHello(string name) { Middsol.CORBA.ORB oOrb = Middsol.CORBA._ORB.init( null, null); // Get CORBA Object via IOR Middsol.CORBA.Object obj = oOrb.string_to_object( "file://c:\\hello.ior" ); // Narrow CORBA Object the Greetings Interface Hello.Greetings oGreetings = Hello.GreetingsHelper.narrow( obj ); // Call hello-Operation return (oGreetings.hello( name )); } using System; using System.Runtime.Remoting; using Middsol; using Hello; namespace RemotingHelloServer { // HelloWorld is a server object that is available // "by-reference". It contains a constructor and a the // "sayHello" method taking a string parameter "name" public class HelloWorld : MarshalByRefObject, IHelloWorld { public string sayHello(string name) { Middsol.CORBA.ORB oOrb = Middsol.CORBA._ORB.init( null, null); // Get CORBA Object via IOR Middsol.CORBA.Object obj = oOrb.string_to_object( "file://c:\\hello.ior" ); // Narrow CORBA Object the Greetings Interface Hello.Greetings oGreetings = Hello.GreetingsHelper.narrow( obj ); // Call hello-Operation return (oGreetings.hello( name )); } Like in Java RMI (& CORBA) – we need to have an implementation of the interface A remote object “by-reference” that implements the IHelloWorld interface A remote object “by-reference” that implements the IHelloWorld interface Implementing the sayHello method Static CORBA client stuff Static CORBA client stuff Use Remoting, ORB and generated Proxy stub (Hello) Use Remoting, ORB and generated Proxy stub (Hello) FINALLY NEW – the sayHello method has changed to become a CORBA client

8 Ingeniørhøjskolen i Århus Slide 8 af 8 The Hello.idl CORBA IDL module Hello { interface Greetings { string hello( in string a_strName); }; module Hello { interface Greetings { string hello( in string a_strName); }; For MiddCor ORB proxy stub compilation: MCidl2cs.exe Hello.idl ALSO NEW – the IDL needed for proxy stub generation (and the server)


Download ppt "Presentation 24 Ultra Simple.NET Remoting to CORBA bridge."

Similar presentations


Ads by Google