// Copyright 2003 Kristopher Johnson #region License // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. #endregion using System; using System.Diagnostics; using System.IO; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Messaging; using System.Threading; using Remoting.Corba; using Remoting.Corba.Channels.Iiop; namespace Remoting.Corba.Examples.HelloServer { // CORBA interface derived from hello.idl generated files _HelloStub.java, HelloPOA.java [CorbaTypeId("IDL:HelloApp/Hello:1.0")] public abstract class Hello: CorbaObject { public abstract string sayHello(string message); [OneWay] public abstract void shutdown(); } // Implementation public class HelloImpl: Hello { protected static ManualResetEvent ShutdownCalled = new ManualResetEvent(false); public static void WaitForShutdown() { ShutdownCalled.WaitOne(); } public override bool is_a(string repositoryId) { if (CorbaServices.GetRepositoryId(typeof(Hello)) == repositoryId) return true; else return false; } public override string sayHello(string message) { Trace.WriteLine("sayHello: " + message); return "Hello "+message+"!"; } public override void shutdown() { Trace.WriteLine("shutdown"); ShutdownCalled.Set(); } } // Application main class HelloServer { static void Main(string[] args) { // create and register channel IiopChannel channel = new IiopChannel(0); ChannelServices.RegisterChannel(channel); // register our implementation RemotingConfiguration.RegisterWellKnownServiceType( typeof(HelloImpl), "Hello", WellKnownObjectMode.Singleton); // determine the IOR string[] uris = channel.GetUrlsForUri("Hello"); string ior = uris[0]; Console.WriteLine("The IOR is: " + ior); // write IOR to output file if ((args.Length >= 2) && (args[0] == "-iorfile")) { string iorFilename = args[1]; using (StreamWriter file = new StreamWriter(iorFilename)) { file.Write(ior); } } // this thread sleeps while requests are handled asynchronously HelloImpl.WaitForShutdown(); // cleanup Console.Error.WriteLine("The Hello server is shutting down"); ChannelServices.UnregisterChannel(channel); } } }