Пример #1
0
        private void ServerQueueOnReceiveCompleted(object sender, ReceiveCompletedEventArgs receiveCompletedEventArgs)
        {
            var queue = (MessageQueue) sender;

            using (Message clientRequest = queue.EndReceive(receiveCompletedEventArgs.AsyncResult))
            {
                var request = clientRequest.Body as BasicMessage;

                if (request != null)
                {
                    Console.WriteLine("Message Received from client:");
                    Console.WriteLine(" - " + request.Content);
                    Console.WriteLine("Sending response in one moment...");
                    Thread.Sleep(1000); // Simulate some long process...

                    using (MessageQueue responseQueue = clientRequest.ResponseQueue) // Note we don't need to know the address.
                    {
                        var response = new BasicMessage
                        {
                            Content = "Server response on " + DateTime.Now.ToShortTimeString()
                        };
                        responseQueue.Send(response);
                    }
                }
            }

            queue.BeginReceive();
        }
Пример #2
0
        private void BtnSendOnClick(object sender, EventArgs eventArgs)
        {
            if (_isDisposed) throw new ObjectDisposedException("Form1");

            // Send a request to the server
            using (var queue = new MessageQueue(@".\private$\TxServerQueue"))
            {
                using (var tx = new MessageQueueTransaction())
                using (var message = new msmq.Message())
                {
                    tx.Begin();
                    var request = new BasicMessage
                    {
                        Content = "Message sent from Basic Client at " + DateTime.Now.ToShortTimeString()
                    };
                    message.Body = request;

                    queue.Send(message, tx);
                    tx.Commit();
                }
            }
        }
Пример #3
0
        private void BtnSendOnClick(object sender, EventArgs eventArgs)
        {
            if (_isDisposed) throw new ObjectDisposedException("Form1");

            // Send a request to the server
            using (var queue = new MessageQueue(@".\private$\BasicServerQueue"))
            {
                using (var message = new msmq.Message())
                {
                    // Tell the server where to send the response
                    message.ResponseQueue = _responseQueue;

                    var request = new BasicMessage
                    {
                        Content = "Message sent from Basic Client at " + DateTime.Now.ToShortTimeString()
                    };
                    message.Body = request;

                    queue.Send(message);
                }
            }
        }