/// <inheritdoc/> public override void Execute(UserSettings settings) { switch (settings.AppSide) { case AppSide.Client: IContract client = CreateClient <IContract>(settings); SysConsole.WriteQuestionLine("Single client instance created!"); SysConsole.WriteLine(); new Thread(() => { SysConsole.WriteInfoLine("[ON] Client request-reply method caller"); while (true) { client.Method("User1"); } }).Start(); new Thread(() => { SysConsole.WriteInfoLine("[ON] Client OneWay method caller"); while (true) { client.MethodOneWay("User2"); Thread.Sleep(1000); } }).Start(); Console.ReadKey(); break; case AppSide.Server: var concurrencyMode = QuestionManager.Choose( new[] { ConcurrencyMode.Single, ConcurrencyMode.Multiple }, s => s.ToString(), "Choose service ConcurrencyMode demonstration:"); var host = concurrencyMode == ConcurrencyMode.Multiple ? CreateServiceHost <IContract, ConcurrencyMultiple>(settings) : CreateServiceHost <IContract, ConcurrencySingle>(settings); host.Open(); SysConsole.WriteInfoLine($"Each one contract method executing at least {ThreadSleepTimeSeconds} SECONDS"); QuestionManager.AwaitingClientConnections(); break; default: throw new ArgumentOutOfRangeException(); } }
/// <inheritdoc/> public override void Execute(UserSettings settings) { switch (settings.AppSide) { case AppSide.Client: var client = CreateClient <IMyService>(settings); SysConsole.WriteLine(); TrySafeCall( () => { SysConsole.WriteQuestionLine($"Calling >> [{nameof(client.MethodFaultContract)}]..."); client.MethodFaultContract(); }); SysConsole.WriteLine(); TrySafeCall( () => { SysConsole.WriteQuestionLine($"Calling >> [{nameof(client.MethodWrongFaultContract)}]..."); client.MethodWrongFaultContract(); }); SysConsole.WriteLine(); TrySafeCall( () => { SysConsole.WriteQuestionLine($"Calling >> [{nameof(client.MethodThrownFaultException)}]..."); client.MethodThrownFaultException(); }); SysConsole.WriteLine(); TrySafeCall( () => { SysConsole.WriteQuestionLine("Validating client service proxy:"); SysConsole.WriteQuestionLine($"Calling >> [{nameof(client.CheckClient)}]..."); SysConsole.WriteLine(client.CheckClient()); }); Console.ReadKey(); break; case AppSide.Server: CreateServiceHost <IMyService, MyService>(settings).Open(); QuestionManager.AwaitingClientConnections(); break; default: throw new ArgumentOutOfRangeException(); } }
public override void Execute(UserSettings settings) { if (!(settings.Binding is BasicHttpBinding)) { SysConsole.WriteErrorLine($"Supports {nameof(BasicHttpBinding)} only."); return; } switch (settings.AppSide) { case AppSide.Client: var clients = QuestionManager.Choose( new[] { 1, 2, 3 }, (o) => o.ToString(), "Choose clients count"); // Creates callback processors for (int i = 0; i < clients; i++) { // proxy client var client = CreateClient <IMyService>(settings); // client thread Task.Factory.StartNew(InitClient, client); } SysConsole.PressAnyKey(); SysConsole.WriteLine(null, 2); break; case AppSide.Server: CreateServiceHost <IMyService, MyService>(settings).Open(); QuestionManager.AwaitingClientConnections(); break; } }
/// <inheritdoc/> public override void Execute(UserSettings settings) { switch (settings.AppSide) { case AppSide.Client: var client = CreateClient <IErrorService>(settings); SysConsole.WriteLine(); TrySafeCall( () => { SysConsole.WriteQuestionLine($"Calling >> [{nameof(client.MethodThrowingException)}]..."); client.MethodThrowingException(); }); TrySafeCall( () => { SysConsole.WriteQuestionLine($"Calling >> [{nameof(client.CheckClient)}]..."); SysConsole.WriteLine(client.CheckClient()); }); Console.ReadKey(); break; case AppSide.Server: var serviceHost = new ServiceHost(typeof(MyErrorService)); var servicePoint = serviceHost.AddServiceEndpoint(typeof(IErrorService), settings.Binding, settings.ServiceUrl); servicePoint.Behaviors.Add(new ErrorBehavior()); serviceHost.Open(); QuestionManager.AwaitingClientConnections(); break; default: throw new ArgumentOutOfRangeException(); } }
public void Dispose() { SysConsole.WriteLine($"Goodbye [{OperationContext.Current?.SessionId}]"); }
/// <inheritdoc/> public void Hello() { SysConsole.WriteLine($"SessionId [{OperationContext.Current?.SessionId}] Call [{++_call}]"); }
public override void WriteLine(string text) { // TODO: Change maybe? SysConsole.WriteLine(text, "^r^7"); }
/// <inheritdoc/> public void SayHello() { SysConsole.WriteLine($"Hello world! The time is {DateTime.Now.ToShortTimeString()}"); }
private void Test() { SysConsole.WriteLine("something"); }
/// <inheritdoc/> public override void Execute(UserSettings settings) { if (settings.Binding.GetType() != typeof(NetTcpBinding)) { SysConsole.WriteLine("Binding should be NetTcpBinding"); return; } var maxConnections = QuestionManager.Choose( new[] { 2, 3, 4, 5 }, s => s.ToString(), "Choose maxConnections number", "NOTE: Please use a same value on client and server sides."); var netTcpBinding = (NetTcpBinding)settings.Binding; netTcpBinding.MaxConnections = maxConnections; SysConsole.WriteQuestionLine($"{netTcpBinding.Name}.MaxConnection = {maxConnections} now"); switch (settings.AppSide) { case AppSide.Client: int clients = 15; SysConsole.WriteLine(); SysConsole.WriteLine(); SysConsole.WriteLine($"Starting {clients} clients."); SysConsole.WriteLine(); // Если нет channel клиентов, которые могу работать со службой, тогда все соединения сбрасываются и maxConnections не работает var holderClient = CreateClient <IMyService>(settings); for (var i = 0; i < clients; i++) { var client = CreateClient <IMyService>(settings); int iLocal = i; PeriodicExecutor(client, (service, j) => { SysConsole.WriteQuestionLine($"Client{iLocal} >> call[{j}]"); service.Method($"Client{iLocal}"); CloseClient(service); return(false); }, 0); } Console.ReadKey(); break; case AppSide.Server: CreateServiceHost <IMyService, MyService>(settings).Open(); SysConsole.WriteQuestionLine("Unlimited method calls with OneWay."); QuestionManager.AwaitingClientConnections(); break; default: throw new ArgumentOutOfRangeException(); } }
public void Method(string name) { SysConsole.WriteLine($"Hello {name}"); Thread.Sleep(5000); }
/// <inheritdoc/> public override void Execute(UserSettings settings) { switch (settings.AppSide) { case AppSide.Client: SysConsole.WriteLine(); SysConsole.WriteQuestionLine("A correct flow when we logged in -> said hello world -> logged out.", 2); while (true) { var client = CreateClient <IMyService>(settings); try { while (true) { var methodName = QuestionManager.Choose( new[] { nameof(IMyService.Login), nameof(IMyService.SayHello), nameof(IMyService.Logout), }, s => s.ToString(), "Choose contract action call"); switch (methodName) { case nameof(IMyService.Login): client.Login(); break; case nameof(IMyService.Logout): client.Logout(); break; case nameof(IMyService.SayHello): client.SayHello(); break; } } } catch (Exception exception) { SysConsole.WriteErrorLine(exception.Message); var answer = QuestionManager.Choose( new[] { "Yes", "No" }, s => s.ToString(), "Create new connection?"); if (answer == "No") { break; } } } break; case AppSide.Server: var service = CreateServiceHost <IMyService, MyService>(settings); service.Open(); SysConsole.WriteQuestion("Service is working."); QuestionManager.AwaitingClientConnections(); break; default: throw new ArgumentOutOfRangeException(); } }
/// <inheritdoc/> public void Logout() { SysConsole.WriteLine("Goodbye my friend"); }
public void Method() { SysConsole.WriteLine($"Hello [{OperationContext.Current?.SessionId}]"); }
public override void WriteLine(string text) { SysConsole.WriteLine(text); }
/// <inheritdoc/> public override void Execute(UserSettings settings) { var correctBindings = new[] { typeof(NetTcpBinding), typeof(WSHttpBinding), typeof(BasicHttpBinding) }; var bindingType = settings.Binding.GetType(); if (!correctBindings.Contains(bindingType)) { SysConsole.WriteLine($"Binding type should be {string.Join(" or ", correctBindings.Select(binding => binding.Name))}"); return; } var reliableSessionFlag = QuestionManager.Choose( new[] { true, false }, s => CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s.ToString()), "Choose reliableSession mode"); SysConsole.WriteLine(); SysConsole.WriteQuestionLine($"ReliableSession mode [{reliableSessionFlag.ToString().ToUpper()}] in use now!", 3); if (bindingType == typeof(NetTcpBinding)) { var netTcp = ((NetTcpBinding)settings.Binding); netTcp.ReliableSession.Enabled = reliableSessionFlag; netTcp.Security.Mode = SecurityMode.None; } else if (bindingType == typeof(WSHttpBinding)) { var wsDual = ((WSHttpBinding)settings.Binding); wsDual.ReliableSession.Enabled = reliableSessionFlag; wsDual.Security.Mode = SecurityMode.None; } else if (bindingType == typeof(BasicHttpBinding)) { SysConsole.WriteLine($"[{settings.Binding.Name}] [{bindingType.Name}] not supports ReliableSession"); } else { throw new NotSupportedException(bindingType.FullName); } switch (settings.AppSide) { case AppSide.Client: var client = CreateClient <IService>(settings); SysConsole.WriteQuestion("Single proxy channel client instance!", 1); int maxCatchs = 3; while (maxCatchs > 0) { try { SysConsole.WriteLine($"Call >> {nameof(IService.Method)}"); client.Method(); Thread.Sleep(2000); } catch (Exception exception) { SysConsole.WriteErrorLine(exception.Message); Thread.Sleep(2000); } try { SysConsole.WriteLine($"Call >> {nameof(IService.OneWayMethodThrowingException)}"); client.OneWayMethodThrowingException(); Thread.Sleep(2000); } catch (Exception exception) { SysConsole.WriteErrorLine(exception.Message); Thread.Sleep(2000); } try { SysConsole.WriteLine($"Call >> {nameof(IService.MethodThrowingException)}"); client.MethodThrowingException(); Thread.Sleep(2000); } catch (Exception exception) { SysConsole.WriteErrorLine(exception.Message); Thread.Sleep(2000); } maxCatchs--; } Console.ReadKey(); break; case AppSide.Server: CreateServiceHost <IService, Service>(settings).Open(); QuestionManager.AwaitingClientConnections(); break; default: throw new ArgumentOutOfRangeException(); } }
/// <inheritdoc/> public void Login() { SysConsole.WriteLine(_isLoggedIn ? "You are already logged in." : "You are welcome!"); _isLoggedIn = true; }