Lesson 6: Receiving the Reply and Ending the Conversation
In this lesson, you will learn to receive the reply message from the target service and end the conversation. Run these steps from a copy of Management Studio that is running on the same computer as the initiator instance the Database Engine.
Copy and paste the following code into a Query Editor window. Then, run it to switch context back to the InstInitiatorDB database where you will receive the reply message and end the conversation.
USE InstInitiatorDB; GO
Copy and paste the following code into a Query Editor window. Then, run it to receive the reply message and end the conversation. The RECEIVE statement retrieves the reply message from the InstInitiatorQueue. The END CONVERSATION statement ends the initiator side of the conversation. The last SELECT statement displays the text of the reply message so that you can confirm it is the same as what was sent in the last step.
DECLARE @RecvReplyMsg NVARCHAR(100); DECLARE @RecvReplyDlgHandle UNIQUEIDENTIFIER; BEGIN TRANSACTION; RECEIVE TOP(1) @RecvReplyDlgHandle = conversation_handle, @RecvReplyMsg = message_body FROM InstInitiatorQueue; END CONVERSATION @RecvReplyDlgHandle; -- Display recieved request. SELECT @RecvReplyMsg AS ReceivedReplyMsg; COMMIT TRANSACTION; GO
This concludes the tutorial. Tutorials are brief overviews and do not describe all available options. Tutorials have simplified logic and error handling to better focus on fundamental operations. To create efficient, reliable, and robust conversations, you need more complex code than the example in this tutorial.