static void SendMessageWithCallback(string message) { try { var context = new InstanceContext(new MessageServiceCallback()); var proxy = new DuplexMessageServiceClient(context); proxy.SetUserNameAndPassword("hhoangvan", "hhoangvan"); proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; var messageDto = new MessageDto() { Message = message, SentAt = DateTime.Now }; proxy.GetAll(); proxy.SendMessage(messageDto); proxy.LogMessage(messageDto); proxy.Close(); } catch (Exception ex) { Console.WriteLine("-----"); while (ex != null) { Console.WriteLine(ex.Message); ex = ex.InnerException; } Console.WriteLine("-----"); } }
public void LogMessage(MessageDto message) { _messageRepository.Add(message); // Simulate processing time Thread.Sleep(new Random().Next(1000, 2001)); }
public void SendMessage(MessageDto message) { if (ServiceCallback != null) { ServiceCallback.NotifyMessage(message); } }
static void AccessService2() { try { var context = new InstanceContext(new MessageServiceCallback()); var proxy = new DuplexMessageServiceClient(context); proxy.SetUserNameAndPassword("hhoangvan", "hhoangvan"); var message = new MessageDto() { Message = "Hello duplex" }; proxy.SendMessage(message); proxy.LogMessage(message); var result = proxy.GetAll(); Console.WriteLine("Results: " + result.Count()); } catch (Exception ex) { Console.WriteLine("-----"); while (ex != null) { Console.WriteLine(ex.Message); ex = ex.InnerException; } Console.WriteLine("-----"); } }
static void AccessService1() { try { var proxy = new MessageServiceClient(); proxy.SetUserNameAndPassword("hhoangvan", "hhoangvan"); var message = new MessageDto() { Message = "Hello request/reply" }; proxy.SendMessage(message); proxy.LogMessage(message); var result = proxy.GetAll(); Console.WriteLine("Results: " + result.Count()); } catch (Exception ex) { Console.WriteLine("-----"); while (ex != null) { Console.WriteLine(ex.Message); ex = ex.InnerException; } Console.WriteLine("-----"); } }
public void SendMessage(MessageDto message) { }
public void NotifyMessage(MessageDto message) { Console.WriteLine("{0} at {1}", message.Message, message.SentAt); }
public void Add(MessageDto message) { Messages.Add(message); }