//# //# Corba Time Client //# $Revision: 1.1 $ //# Copyright 2004 by Eric Y. Theriault //# All Rights Reserved. //# http://www.eyt.ca/CORBA //# using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Services; using System.Runtime.Remoting.Channels; using Ch.Elca.Iiop; using Ch.Elca.Iiop.Services; namespace ca.eyt.corba { /// /// Implements a class to acquire the Time from a CORBA server. /// public class TimeClient { /// /// Main. /// [System.STAThread] public static void Main( string[] args ) { try { String ior = null; String iorFile = "time.ior"; // Create and Initialize the ORB CorbaInit orb = CorbaInit.GetInit(); // Read in the file try { using ( System.IO.StreamReader reader = new System.IO.StreamReader( iorFile ) ) { ior = reader.ReadLine(); } } catch ( Exception e ) { System.Console.Error.WriteLine( iorFile + " raised an exception: " + e.Message ); System.Environment.Exit( 1 ); } // Register client channel IiopClientChannel clientChannel = new IiopClientChannel(); ChannelServices.RegisterChannel( clientChannel ); // Resolve the ior into an object. TimeTools.Time timeImpl = RemotingServices.Connect( typeof( TimeTools.Time ), ior ) as TimeTools.Time; // OK. Let's call the Time interface's methods. TimeTools.TimeOfDay time = timeImpl.getTime(); System.Console.Out.WriteLine( "Time server's time is: {0}:{1}:{2}", time.hour, time.minute, time.second ); } catch ( System.Exception e ) { System.Console.WriteLine( "Exception: " + e.Message ); System.Console.WriteLine( e.StackTrace.ToString() ); System.Environment.Exit( 1 ); } System.Environment.Exit( 0 ); } } }