private void doRequest(Operation operation, int leftOperand, int rightOperand) { // Create the request message IMessage requestMessage = ContextFactory.Instance.CreateMessage(); requestMessage.Destination = ContextFactory.Instance.CreateTopic(requestTopicStr); requestMessage.DeliveryMode = MessageDeliveryMode.Direct; /* explicitly set to MessageDeliveryMode.Direct */ IStreamContainer stream = SDTUtils.CreateStream(requestMessage, 256); stream.AddInt8((short)operation); stream.AddInt32(leftOperand); stream.AddInt32(rightOperand); // Send the request message to the service or RRDirectReplier IMessage replyMessage = null; int timeout = 2000; /* 2 secs*/ Console.WriteLine("\nSending request message, waiting for {0} msecs for a reply (make sure that RRDirectReply is running) ...", timeout); Console.WriteLine(ARITHMETIC_EXPRESSION, leftOperand, operation.ToString(), rightOperand, "?"); if (session.SendRequest(requestMessage, out replyMessage, 2000) == ReturnCode.SOLCLIENT_OK) { // Got a reply, format and print the response message Console.WriteLine("\nGot reply message"); IStreamContainer respStream = (IStreamContainer)SDTUtils.GetContainer(replyMessage); if (respStream != null) { ISDTField status = respStream.GetNext(); if (status.Type == SDTFieldType.BOOL) { if (((bool)status.Value)) { Console.WriteLine(ARITHMETIC_EXPRESSION, leftOperand, operation.ToString(), rightOperand, respStream.GetNext().Value.ToString()); } else { Console.WriteLine(ARITHMETIC_EXPRESSION, leftOperand, operation.ToString(), rightOperand, "operation failed"); } } } } else { Console.WriteLine("Request failed"); } if (requestMessage != null) { // It is a good practice to dispose of messages once done using them requestMessage.Dispose(); } }
private void doRequest(IDestination requestDestination, IDestination replyToQueue, Operation operation, int leftOperand, int rightOperand) { // Create the request message IMessage requestMessage = ContextFactory.Instance.CreateMessage(); requestMessage.Destination = requestDestination; requestMessage.DeliveryMode = MessageDeliveryMode.Persistent; requestMessage.ReplyTo = replyToQueue; IStreamContainer stream = SDTUtils.CreateStream(requestMessage, 256); stream.AddInt8((short)operation); stream.AddInt32(leftOperand); stream.AddInt32(rightOperand); // Send the request message to the service or RRDirectReplier int timeout = 2000; /* 2 secs*/ Console.WriteLine("\nSending request message, waiting for {0} msecs for a reply (make sure that RRGuaranteedReplier is running) ...", timeout); session.Send(requestMessage); Console.WriteLine(ARITHMETIC_EXPRESSION, leftOperand, operation.ToString(), rightOperand, "?"); if (waitForReply.WaitOne(timeout)) { // Got a reply, format and print the response message Console.WriteLine("\nGot reply message"); IStreamContainer respStream = (IStreamContainer)SDTUtils.GetContainer(replyMessage); if (respStream != null) { ISDTField status = respStream.GetNext(); if (status.Type == SDTFieldType.BOOL) { if (((bool)status.Value)) { Console.WriteLine(ARITHMETIC_EXPRESSION, leftOperand, operation.ToString(), rightOperand, respStream.GetNext().Value.ToString()); } else { Console.WriteLine(ARITHMETIC_EXPRESSION, leftOperand, operation.ToString(), rightOperand, "operation failed"); } } else { Console.WriteLine("Failed to parse the request message, here's a message dump:\n{0}", replyMessage.Dump()); } } else { Console.WriteLine("Failed to parse the request message, here's a message dump:\n{0}", replyMessage.Dump()); } } else { Console.WriteLine(string.Format("Failed to receive a reply within {0} msecs", timeout)); } // It is a good practice to dispose of messages once done using them if (requestMessage != null) { requestMessage.Dispose(); } if (replyMessage != null) { replyMessage.Dispose(); } }