public static ITestRunner RegisterAsServer(ITestOutput output, Options options) { var host = new ServiceHost(output); int i; for (i = 0; i < 50; i += 10) { try { host.AddServiceEndpoint(typeof(ITestOutput), BindingFactory(), "http://localhost:" + (StartPort + i) + "/"); break; } catch (AddressAlreadyInUseException) { } } host.Open(); var start = DateTime.Now; Exception final = null; var res = new ChannelFactory<ITestRunner>(BindingFactory(), "http://localhost:" + (StartPort + i + 1) + "/").CreateChannel(); while (DateTime.Now - start < TimeSpan.FromSeconds(5)) { try { res.Ping(); return res; } catch (Exception e) { final = e; } } throw final; }