public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.ColoredConsole() .CreateLogger(); Console.Title = "Halibut Client"; var hostName = args.FirstOrDefault() ?? "localhost"; var port = args.Skip(1).FirstOrDefault() ?? "8433"; var certificate = new X509Certificate2("HalibutClient.pfx"); using (var runtime = new HalibutRuntime(certificate)) { Console.WriteLine("creating calculator"); var calculator = runtime.CreateClient<ICalculatorService>("https://" + hostName + ":" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC"); Console.WriteLine("making call 1"); var result = calculator.Add(12, 18); Console.WriteLine("making call 2"); result = calculator.Add(12, 18); Console.WriteLine("12 + 18 = " + result); Console.ReadKey(); } }
public void OctopusCanSendMessagesToWebSocketPollingTentacle() { const int octopusPort = 8450; AddSslCertToLocalStoreAndRegisterFor("0.0.0.0:" + octopusPort); try { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling)) { octopus.ListenWebSocket($"https://+:{octopusPort}/Halibut"); octopus.Trust(Certificates.TentaclePollingPublicThumbprint); tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri($"wss://localhost:{octopusPort}/Halibut"), Certificates.SslThumbprint)); var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint); for (var i = 0; i < 2000; i++) { echo.SayHello("Deploy package A" + i).Should().Be("Deploy package A" + i + "..."); } } } finally { RemoveSslCertBindingFor("0.0.0.0:" + octopusPort); } }
public void StartClient() { var DaClient = new HalibutRuntime(Configuration.ClientCertificate); var DaService = DaClient.CreateClient <ITestService>(Configuration.ClientEndpoint, Configuration.ServerCertificate.Thumbprint); var IntTester = DaService.Add(1, 5); var StringSender = DaService.Send("Hi mom"); }
public Task StartAsync(CancellationToken cancellationToken) { var certificate = new X509Certificate2(_options.CertificateFile); _runtime = new HalibutRuntime(_serviceFactory, certificate, _trustProvider); if (_options.Trust.Count > 0) { foreach (var item in _options.Trust) { _trustProvider.Add(item); } } _runtime.OnUnauthorizedClientConnect = _options.OnUnauthorizedClientConnect; switch (_options.Mode) { case HalibutServerMode.Listening: _runtime.Listen(_options.Listen.EndPoint); break; case HalibutServerMode.Polling: _runtime.Poll(new Uri($"poll://{_options.Polling.Subscription}"), new ServiceEndPoint(new Uri(_options.Polling.BaseUri), _options.Polling.RemoteThumbPrint, _options.ProxyDetails)); break; case HalibutServerMode.WebSocketPolling: _runtime.Poll(new Uri($"poll://{_options.Polling.Subscription}"), new ServiceEndPoint(new Uri(_options.Polling.BaseUri), _options.Polling.RemoteThumbPrint, _options.ProxyDetails)); break; } return(Task.CompletedTask); }
public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.ColoredConsole() .CreateLogger(); Console.Title = "Halibut Client"; var hostName = args.FirstOrDefault() ?? "localhost"; var port = args.Skip(1).FirstOrDefault() ?? "8433"; var certificate = new X509Certificate2("HalibutClient.pfx"); using (var runtime = new HalibutRuntime(certificate)) { Console.WriteLine("creating calculator"); var calculator = runtime.CreateClient <ICalculatorService>("https://" + hostName + ":" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC"); Console.WriteLine("making call 1"); var result = calculator.Add(12, 18); Console.WriteLine("making call 2"); result = calculator.Add(12, 18); Console.WriteLine("12 + 18 = " + result); Console.ReadKey(); } }
public void OctopusCanSendMessagesToWebSocketPollingTentacle() { var services = GetDelegateServiceFactory(); const int octopusPort = 8450; AddSslCertToLocalStoreAndRegisterFor("0.0.0.0:" + octopusPort); try { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling)) { octopus.ListenWebSocket($"https://+:{octopusPort}/Halibut"); octopus.Trust(Certificates.TentaclePollingPublicThumbprint); tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri($"wss://localhost:{octopusPort}/Halibut"), Certificates.SslThumbprint)); var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint); for (var i = 0; i < 2000; i++) { echo.SayHello("Deploy package A" + i).Should().Be("Deploy package A" + i + "..."); } } } catch (NotSupportedException nse) when(nse.Message == "The netstandard build of this library cannot act as the client in a WebSocket polling setup") { Assert.Inconclusive("This test cannot run on the netstandard build"); } finally { RemoveSslCertBindingFor("0.0.0.0:" + octopusPort); } }
public Task StopAsync(CancellationToken cancellationToken) { _runtime.Dispose(); _runtime = null; return(Task.CompletedTask); }
const string SslCertificateThumbprint = "6E5C6492129B75A4C83E1A23797AF6344092E5C2"; // For WebSockets. This is different to the internally configured thumbprint public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.ColoredConsole() .MinimumLevel.Warning() .CreateLogger(); Console.Title = "Halibut Server"; var certificate = new X509Certificate2("HalibutServer.pfx"); var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433); var services = new DelegateServiceFactory(); services.Register <ICalculatorService>(() => new CalculatorService()); using (var server = new HalibutRuntime(services, certificate)) { //Although this is the "Server" because it is the thing handling a request //in Octopus terms, this would be the Tentacle, being asked to do some work //Begin Listening Setup //server.Listen(endPoint); //server.Trust("2074529C99D93D5955FEECA859AEAC6092741205"); //End Listening Setup //Begin Polling Setup //server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:8433"), "2074529C99D93D5955FEECA859AEAC6092741205")); //End Polling Setup //Begin WebSocket Polling Setup server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("wss://localhost:8433/Halibut"), SslCertificateThumbprint)); //End WebSocket Polling Setup Console.WriteLine("Server listening on port 8433. Type 'exit' to quit, or 'cls' to clear..."); while (true) { var line = Console.ReadLine(); if (string.Equals("cls", line, StringComparison.OrdinalIgnoreCase)) { Console.Clear(); continue; } if (string.Equals("q", line, StringComparison.OrdinalIgnoreCase)) { return; } if (string.Equals("exit", line, StringComparison.OrdinalIgnoreCase)) { return; } Console.WriteLine("Unknown command. Enter 'q' to quit."); } } }
static void RunListeningClient(X509Certificate2 clientCertificate, int port, string remoteThumbprint, bool expectSuccess = true) { using (var runtime = new HalibutRuntime(clientCertificate)) { var calculator = runtime.CreateClient <ICalculatorService>($"https://localhost:{port}/", remoteThumbprint); MakeRequest(calculator, "listening", expectSuccess); } }
public void ConnectingOverHttpShouldFailQuickly() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var listenPort = octopus.Listen(); Assert.Throws<WebException>(() => DownloadStringIgnoringCertificateValidation("http://localhost:" + listenPort)); } }
public OctopusForm() { InitializeComponent(); log = new Logger(logBox); var services = new DelegateServiceFactory(); serverHalibutRuntime = new HalibutRuntime(services, new X509Certificate2("OctopusServer.pfx")); }
public void FailOnInvalidPort() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var echo = octopus.CreateClient<IEchoService>("https://google.com:88", Certificates.TentacleListeningPublicThumbprint); var ex = Assert.Throws<HalibutClientException>(() => echo.Crash()); Assert.That(ex.Message, Does.Contain("when sending a request to 'https://google.com:88/', before the request")); } }
public void FailOnInvalidHostname() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var echo = octopus.CreateClient <IEchoService>("https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000", Certificates.TentacleListeningPublicThumbprint); var ex = Assert.Throws <HalibutClientException>(() => echo.Crash()); ex.Message.Should().Contain("when sending a request to 'https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000/', before the request").And.Contain("No such host is known"); } }
public void FailsWhenSendingToPollingMachineButNothingPicksItUp() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint); var error = Assert.Throws <HalibutClientException>(() => echo.SayHello("Paul")); error.Message.Should().Contain("the polling endpoint did not collect the request within the allowed time"); } }
public void FailsWhenSendingToPollingMachineButNothingPicksItUp() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint); var error = Assert.Throws<HalibutClientException>(() => echo.SayHello("Paul")); Assert.That(error.Message, Does.Contain("the polling endpoint did not collect the request within the allowed time")); } }
public void FailOnInvalidPort() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var echo = octopus.CreateClient <IEchoService>("https://google.com:88", Certificates.TentacleListeningPublicThumbprint); var ex = Assert.Throws <HalibutClientException>(() => echo.Crash()); ex.Message.Should().Contain("when sending a request to 'https://google.com:88/', before the request"); } }
public void FailOnInvalidHostname() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var echo = octopus.CreateClient<IEchoService>("https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000", Certificates.TentacleListeningPublicThumbprint); var ex = Assert.Throws<HalibutClientException>(() => echo.Crash()); Assert.That(ex.Message, Does.Contain("when sending a request to 'https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000/', before the request").And.Contains("No such host is known")); } }
public void StartServer() { var services = new DelegateServiceFactory(); services.Register <ITestService>(() => new TestService()); var DaServer = new HalibutRuntime(services, Configuration.ServerCertificate); DaServer.Listen(1337); DaServer.Trust(Configuration.ClientCertificate.Thumbprint); }
protected override void ProcessRecord() { using (var runtime = new HalibutRuntime(Configuration.ClientCertificate)) { var pairing = runtime.CreateClient <IPairingService>(Configuration.ClientEndpoint, Configuration.ServerCertificate.Thumbprint); pairing.DualShockDevices.ToList().ForEach(WriteObject); } }
static int RunServer() { var services = new DelegateServiceFactory(); services.Register<ICalculatorService>(() => new CalculatorService()); var server = new HalibutRuntime(services, ServerCertificate); server.Trust("2074529C99D93D5955FEECA859AEAC6092741205"); var port = server.Listen(); return port; }
void DoConnectingOverHttpShouldFailQuickly() { var services = GetDelegateServiceFactory(); using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var listenPort = octopus.Listen(); Assert.ThrowsAsync <HttpRequestException>(() => DownloadStringIgnoringCertificateValidation("http://localhost:" + listenPort)); } }
public void OctopusCanDiscoverTentacle() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening)) { var tentaclePort = tentacleListening.Listen(); var info = octopus.Discover(new Uri("https://localhost:" + tentaclePort)); Assert.That(info.RemoteThumbprint, Is.EqualTo(Certificates.TentacleListeningPublicThumbprint)); } }
public TentacleForm() { InitializeComponent(); log = new Logger(textBox1); var tentacleServices = new DelegateServiceFactory(); tentacleServices.Register<IHealthCheckService>(() => new HealthCheck(log)); tentacleHalibutRuntime = new HalibutRuntime(tentacleServices, new X509Certificate2("OctopusTentacle.pfx")); }
public void SetUp() { var services = new DelegateServiceFactory(); services.Register<IEchoService>(() => new EchoService()); tentacle = new HalibutRuntime(services, Certificates.TentacleListening); var tentaclePort = tentacle.Listen(); tentacle.Trust(Certificates.OctopusPublicThumbprint); endpoint = new ServiceEndPoint("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint); log = new InMemoryConnectionLog(endpoint.ToString()); HalibutLimits.ConnectionErrorRetryTimeout = TimeSpan.MaxValue; }
void DoConnectingOverHttpShouldFailQuickly() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var listenPort = octopus.Listen(); #if NET40 Assert.Throws <WebException>(() => DownloadStringIgnoringCertificateValidation("http://localhost:" + listenPort)); #else Assert.Throws <HttpRequestException>(() => DownloadStringIgnoringCertificateValidation("http://localhost:" + listenPort)); #endif } }
public TentacleForm() { InitializeComponent(); log = new Logger(textBox1); var tentacleServices = new DelegateServiceFactory(); tentacleServices.Register <IHealthCheckService>(() => new HealthCheck(log)); tentacleHalibutRuntime = new HalibutRuntime(tentacleServices, new X509Certificate2("OctopusTentacle.pfx")); }
public void SupportsHttpsGet(string uriFormat) { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var listenPort = octopus.Listen(); var uri = uriFormat.Replace("{machine}", Environment.MachineName).Replace("{port}", listenPort.ToString()); var result = DownloadStringIgnoringCertificateValidation(uri); result.Should().Be("<html><body><p>Hello!</p></body></html>"); } }
public void FailOnInvalidHostname() { var services = GetStubDelegateServiceFactory(); using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var echo = octopus.CreateClient <IEchoService>("https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000", Certificates.TentacleListeningPublicThumbprint); var ex = Assert.Throws <HalibutClientException>(() => echo.Crash()); ex.Message.Should().Contain("when sending a request to 'https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000/', before the request") .And.Contain(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "No such host is known" : "No such device or address"); } }
public void FailWhenListeningServerPresentsWrongCertificate() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening)) { var tentaclePort = tentacleListening.Listen(); tentacleListening.Trust(Certificates.OctopusPublicThumbprint); var echo = octopus.CreateClient <IEchoService>("https://localhost:" + tentaclePort, Certificates.TentaclePollingPublicThumbprint); var ex = Assert.Throws <HalibutClientException>(() => echo.SayHello("World")); } }
public void FailWhenServerThrowsAnException() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening)) { var tentaclePort = tentacleListening.Listen(); tentacleListening.Trust(Certificates.OctopusPublicThumbprint); var echo = octopus.CreateClient <IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint); var ex = Assert.Throws <HalibutClientException>(() => echo.Crash()); ex.Message.Should().Contain("at Halibut.Tests.TestServices.EchoService.Crash()").And.Contain("divide by zero"); } }
static int RunServer() { var services = new DelegateServiceFactory(); services.Register <ICalculatorService>(() => new CalculatorService()); var server = new HalibutRuntime(services, ServerCertificate); server.Trust("2074529C99D93D5955FEECA859AEAC6092741205"); var port = server.Listen(); return(port); }
public SecureClientFixture() { var services = new DelegateServiceFactory(); services.Register <IEchoService>(() => new EchoService()); tentacle = new HalibutRuntime(services, Certificates.TentacleListening); var tentaclePort = tentacle.Listen(); tentacle.Trust(Certificates.OctopusPublicThumbprint); endpoint = new ServiceEndPoint("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint); log = new InMemoryConnectionLog(endpoint.ToString()); HalibutLimits.ConnectionErrorRetryTimeout = TimeSpan.MaxValue; }
static void RunClient(int port) { using (var runtime = new HalibutRuntime(ClientCertificate)) { var calculator = runtime.CreateClient <ICalculatorService>("https://localhost:" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC"); for (int i = 0; i < RequestsPerClient; i++) { var result = calculator.Add(12, 18); Debug.Assert(result == 30); } } }
public void FailWhenServerThrowsAnException() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening)) { var tentaclePort = tentacleListening.Listen(); tentacleListening.Trust(Certificates.OctopusPublicThumbprint); var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint); var ex = Assert.Throws<HalibutClientException>(() => echo.Crash()); Assert.That(ex.Message, Does.Contain("at Halibut.Tests.TestServices.EchoService.Crash()").And.Contains("divide by zero")); } }
static void RunClient(int port) { using (var runtime = new HalibutRuntime(ClientCertificate)) { var calculator = runtime.CreateClient<ICalculatorService>("https://localhost:" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC"); for (int i = 0; i < RequestsPerClient; i++) { var result = calculator.Add(12, 18); Debug.Assert(result == 30); } } }
public void FailWhenListeningServerPresentsWrongCertificate() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening)) { var tentaclePort = tentacleListening.Listen(); tentacleListening.Trust(Certificates.OctopusPublicThumbprint); var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentaclePollingPublicThumbprint); var ex = Assert.Throws<HalibutClientException>(() => echo.SayHello("World")); } }
public void OctopusCanDiscoverTentacle() { var services = GetDelegateServiceFactory(); using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening)) { var tentaclePort = tentacleListening.Listen(); var info = octopus.Discover(new Uri("https://localhost:" + tentaclePort)); info.RemoteThumbprint.Should().Be(Certificates.TentacleListeningPublicThumbprint); } }
public void CanSetCustomFriendlyHtmlPage(string html, string expectedResult = null) { expectedResult = expectedResult ?? html; // Handle the null case which reverts to default html using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { octopus.SetFriendlyHtmlPageContent(html); var listenPort = octopus.Listen(); var result = DownloadStringIgnoringCertificateValidation("https://localhost:" + listenPort); Assert.That(result, Is.EqualTo(expectedResult)); } }
public void SetUp() { var services = new DelegateServiceFactory(); services.Register <IEchoService>(() => new EchoService()); tentacle = new HalibutRuntime(services, Certificates.TentacleListening); var tentaclePort = tentacle.Listen(); tentacle.Trust(Certificates.OctopusPublicThumbprint); endpoint = new ServiceEndPoint("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint) { ConnectionErrorRetryTimeout = TimeSpan.MaxValue }; }
public void CanSetCustomFriendlyHtmlPage(string html, string expectedResult = null) { expectedResult = expectedResult ?? html; // Handle the null case which reverts to default html using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { octopus.SetFriendlyHtmlPageContent(html); var listenPort = octopus.Listen(); var result = DownloadStringIgnoringCertificateValidation("https://localhost:" + listenPort); result.Should().Be(expectedResult); } }
protected override void ProcessRecord() { if (!string.IsNullOrEmpty(HostAddress)) { using (var runtime = new HalibutRuntime(Configuration.ClientCertificate)) { var pairing = runtime.CreateClient <IPairingService>(Configuration.ClientEndpoint, Configuration.ServerCertificate.Thumbprint); var host = new UniqueAddress(HostAddress); pairing.Pair(pairing.DualShockDevices.First(d => d.Equals(Device)), host); } } }
public void FailWhenServerThrowsAnExceptionOnPolling() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling)) { var octopusPort = octopus.Listen(); octopus.Trust(Certificates.TentaclePollingPublicThumbprint); tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint)); var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint); var ex = Assert.Throws <HalibutClientException>(() => echo.Crash()); ex.Message.Should().Contain("at Halibut.Tests.TestServices.EchoService.Crash()").And.Contain("divide by zero"); } }
public void OctopusCanSendMessagesToPollingTentacle() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling)) { var octopusPort = octopus.Listen(); octopus.Trust(Certificates.TentaclePollingPublicThumbprint); tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint)); var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint); for (var i = 0; i < 2000; i++) { Assert.That(echo.SayHello("Deploy package A" + i), Is.EqualTo("Deploy package A" + i + "...")); } } }
public void OctopusCanSendMessagesToListeningTentacle() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening)) { var tentaclePort = tentacleListening.Listen(); tentacleListening.Trust(Certificates.OctopusPublicThumbprint); var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint); Assert.That(echo.SayHello("Deploy package A"), Is.EqualTo("Deploy package A...")); var watch = Stopwatch.StartNew(); for (var i = 0; i < 2000; i++) { Assert.That(echo.SayHello("Deploy package A"), Is.EqualTo("Deploy package A...")); } Console.WriteLine("Complete in {0:n0}ms", watch.ElapsedMilliseconds); } }
public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.ColoredConsole() .CreateLogger(); Console.Title = "Halibut Server"; var certificate = new X509Certificate2("HalibutServer.pfx"); var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433); var services = new DelegateServiceFactory(); services.Register<ICalculatorService>(() => new CalculatorService()); using (var server = new HalibutRuntime(services, certificate)) { server.Listen(endPoint); server.Trust("2074529C99D93D5955FEECA859AEAC6092741205"); Console.WriteLine("Server listening on port 8433. Type 'exit' to quit, or 'cls' to clear..."); while (true) { var line = Console.ReadLine(); if (string.Equals("cls", line, StringComparison.OrdinalIgnoreCase)) { Console.Clear(); continue; } if (string.Equals("q", line, StringComparison.OrdinalIgnoreCase)) return; if (string.Equals("exit", line, StringComparison.OrdinalIgnoreCase)) return; Console.WriteLine("Unknown command. Enter 'q' to quit."); } } }
public void SupportsHttpsGet(string uriFormat) { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var listenPort = octopus.Listen(); var uri = uriFormat.Replace("{machine}", Environment.MachineName).Replace("{port}", listenPort.ToString()); var result = DownloadStringIgnoringCertificateValidation(uri); Assert.That(result, Is.EqualTo("<html><body><p>Hello!</p></body></html>")); } }
public void FailWhenServerThrowsAnExceptionOnPolling() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling)) { var octopusPort = octopus.Listen(); octopus.Trust(Certificates.TentaclePollingPublicThumbprint); tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint)); var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint); var ex = Assert.Throws<HalibutClientException>(() => echo.Crash()); Assert.That(ex.Message, Is.StringContaining("at Halibut.Tests.TestServices.EchoService.Crash()").And.StringContaining("divide by zero")); } }
public void StreamsCanBeSentToListeningWithProgressReporting() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening)) { var tentaclePort = tentacleListening.Listen(); tentacleListening.Trust(Certificates.OctopusPublicThumbprint); var progressReported = new List<int>(); var data = new byte[1024 * 1024 * 16 + 15]; new Random().NextBytes(data); var stream = new MemoryStream(data); var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint); var count = echo.CountBytes(DataStream.FromStream(stream, progressReported.Add)); Assert.That(count, Is.EqualTo(1024 * 1024 * 16 + 15)); CollectionAssert.AreEqual(Enumerable.Range(1, 100).ToList(), progressReported); } }
public void StreamsCanBeSentToListening() { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening)) { var tentaclePort = tentacleListening.Listen(); tentacleListening.Trust(Certificates.OctopusPublicThumbprint); var data = new byte[1024 * 1024 + 15]; new Random().NextBytes(data); var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint); for (var i = 0; i < 100; i++) { var count = echo.CountBytes(DataStream.FromBytes(data)); Assert.That(count, Is.EqualTo(1024 * 1024 + 15)); } } }
public void SupportsHttpsGet(string uriFormat) { using (var octopus = new HalibutRuntime(services, Certificates.Octopus)) { var listenPort = octopus.Listen(); using (var webClient = new WebClient()) { try { // We need to ignore server certificate validation errors - the server certificate is self-signed ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true; var result = webClient.DownloadString(uriFormat.Replace("{machine}", Environment.MachineName).Replace("{port}", listenPort.ToString())); Assert.That(result, Is.EqualTo("<html><body><p>Hello!</p></body></html>")); } finally { // And restore it back to default behaviour ServicePointManager.ServerCertificateValidationCallback = null; } } } }
public void SupportsDifferentServiceContractMethods() { services.Register<ISupportedServices>(() => new SupportedServices()); using (var octopus = new HalibutRuntime(Certificates.Octopus)) using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening)) { tentacleListening.Trust(Certificates.OctopusPublicThumbprint); var tentaclePort = tentacleListening.Listen(); var echo = octopus.CreateClient<ISupportedServices>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint); echo.MethodReturningVoid(12, 14); Assert.That(echo.Hello(), Is.EqualTo("Hello")); Assert.That(echo.Hello("a"), Is.EqualTo("Hello a")); Assert.That(echo.Hello("a", "b"), Is.EqualTo("Hello a b")); Assert.That(echo.Hello("a", "b", "c"), Is.EqualTo("Hello a b c")); Assert.That(echo.Hello("a", "b", "c", "d"), Is.EqualTo("Hello a b c d")); Assert.That(echo.Hello("a", "b", "c", "d", "e"), Is.EqualTo("Hello a b c d e")); Assert.That(echo.Hello("a", "b", "c", "d", "e", "f"), Is.EqualTo("Hello a b c d e f")); Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g"), Is.EqualTo("Hello a b c d e f g")); Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h"), Is.EqualTo("Hello a b c d e f g h")); Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i"), Is.EqualTo("Hello a b c d e f g h i")); Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"), Is.EqualTo("Hello a b c d e f g h i j")); Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"), Is.EqualTo("Hello a b c d e f g h i j k")); Assert.That(echo.Add(1, 2), Is.EqualTo(3)); Assert.That(echo.Add(1.00, 2.00), Is.EqualTo(3.00)); Assert.That(echo.Add(1.10M, 2.10M), Is.EqualTo(3.20M)); Assert.That(echo.Ambiguous("a", "b"), Is.EqualTo("Hello string")); Assert.That(echo.Ambiguous("a", new Tuple<string, string>("a", "b")), Is.EqualTo("Hello tuple")); var ex = Assert.Throws<HalibutClientException>(() => echo.Ambiguous("a", (string)null)); Assert.That(ex.Message, Is.StringContaining("Ambiguous")); } }