Пример #1
0
        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("-----");
            }
        }
Пример #2
0
        public void LogMessage(MessageDto message)
        {
            _messageRepository.Add(message);

            // Simulate processing time
            Thread.Sleep(new Random().Next(1000, 2001));
        }
Пример #3
0
 public void SendMessage(MessageDto message)
 {
     if (ServiceCallback != null)
     {
         ServiceCallback.NotifyMessage(message);
     }
 }
Пример #4
0
        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("-----");
            }
        }
Пример #5
0
        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("-----");
            }
        }
Пример #6
0
 public void SendMessage(MessageDto message)
 {
 }
 public void NotifyMessage(MessageDto message)
 {
     Console.WriteLine("{0} at {1}", message.Message, message.SentAt);
 }
Пример #8
0
 public void Add(MessageDto message)
 {
     Messages.Add(message);
 }