static void Main(string[] args) { ServiceHost host = null; try { using (host = new ServiceHost(typeof(Test))) { host.Open(); Thread.Sleep(2500); Console.WriteLine("\npress any key to continue ...\n"); Console.ReadLine(); var testCallback = new TestCallback(); var context = new InstanceContext(testCallback); // action worker(1234567890, "gaga", context); Console.WriteLine("\n+++ press any key to close a ServiceHost +++\n"); Console.ReadLine(); context.Close(); host.Close(); } } catch (CommunicationException ex) { if (host != null) { host.Abort(); } Console.WriteLine(ex.Message); Console.ReadLine(); } catch (Exception ex) { if (host != null) { host.Abort(); } Console.WriteLine(ex); Console.ReadLine(); } finally { Console.WriteLine("\n*** press any key to exit ... ***\n"); Console.ReadLine(); } }
static void Main(string[] args) { ServiceHost host = null; try { using (host = new ServiceHost(typeof(Test))) { host.Open(); Thread.Sleep(2500); Console.WriteLine("\npress any key to continue ...\n"); Console.ReadLine(); var testCallback = new TestCallback(); var context = new InstanceContext(testCallback); // action worker(1234567890, "gaga", context); Console.WriteLine("\n+++ press any key to close a ServiceHost +++\n"); Console.ReadLine(); context.Close(); host.Close(); } } catch (CommunicationException ex) { if (host != null) host.Abort(); Console.WriteLine(ex.Message); Console.ReadLine(); } catch (Exception ex) { if (host != null) host.Abort(); Console.WriteLine(ex); Console.ReadLine(); } finally { Console.WriteLine("\n*** press any key to exit ... ***\n"); Console.ReadLine(); } }