Broker 10.15 | webMethods Broker Documentation | webMethods Broker Messaging Programmer's Guide | Coding Messaging Client Applications | C# Messaging Clients | Application Code | Linking a Reply to a Request Message
 
Linking a Reply to a Request Message
To configure a request-reply message pair, you need to link the two together through application code.
Because each request message expects a reply, the MsgReplyTo field of the request message must be set to the destination to which the reply will be sent. In this example, you set it to the replyQueue (of type Queue) declared in the RequestorApplication class definition, as shown in the following line of code. The message object message is the request message:

reply.MsgCorrelationID = message.MsgMessageID;
Console.WriteLine("OnMessage: Sending reply");
sender.Send(message.MsgReplyTo, reply);
...
Next, in the server application, in the message listener's OnMessage delegate, the message ID header information of the request message is copied to a field in the reply message.
reply.MsgCorrelationID = message.MsgMessageID;
The following figure summarizes the relationships that must be coded between the request and reply messages:
After the request and reply messages are linked, a send is issued for the reply message; however, the message will not be sent until an explicit commit is executed. This is because the session to which the reply message belongs is defined as transacted in ServerApplication.OnMessage().
sender.send(message.MsgReplyTo, reply);
In the requestor application, in LookupCustomerInfo(), the MsgMessageID header field value for the request message is saved for later use as a means of validating the reply.
String pendingMessageID = msg.MsgMessageID;
The method then validates that the reply is linked to the proper request message (checks to see which reply it is) and initiates further processing of the reply.
while (true)
{
IMessage replyMessage = receiver.Receive(REPLY_WAIT_TIME);
...
if (!pendingMessagID.Equals(replyMessage.MsgCorrelationID,
StringComparison.InvariantCultureIgnoreCase)) {
continue; }
if (replyMessage is IMapMessage) {
ProcessDetailedReply((IMapMessage) replyMessage); }
else if (replyMessage is ITextMessage) {
ProcessErrorReply((ITextMessage) replyMessage);
}