Here is the sample SQL script to create a simple queue in SQL Server 2005:
-- Needed to send messages!CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'MyPassword'; GO-- All messages need to be typed.CREATE MESSAGE TYPE[//DEVELOP-ONE.COM/schemas/Test/XmlMessage]VALIDATION = VALID_XML;GO-- Create a contractCREATE CONTRACT [//DEVELOP-ONE.COM/schemas/Test/BasicXmlQueueContract] ( [//DEVELOP-ONE.COM/schemas/Test/XmlMessage] SENT BY ANY ) ; GO -- Create a queue which is turned on and which retains-- messages in the database. CREATE QUEUE BasicXmlQueue WITH STATUS=ON, RETENTION=ON;GO-- Create the service needed to send messages.CREATE SERVICE [//DEVELOP-ONE.COM/Sql/Services/Test/BasicXmlService]ON QUEUE [dbo].[BasicXmlQueue]([//DEVELOP-ONE.COM/schemas/Test/BasicXmlQueueContract]) ;GO-- Create a stored procedure to send a message CREATE PROCEDURE SendXMLMessage@MessageContent XML ASBEGINDECLARE @dialog_handle UNIQUEIDENTIFIER;BEGIN DIALOG CONVERSATION @dialog_handleFROM SERVICE [//DEVELOP-ONE.COM/Sql/Services/Test/BasicXmlService]TO SERVICE '//DEVELOP-ONE.COM/Sql/Services/Test/BasicXmlService'ON CONTRACT [//DEVELOP-ONE.COM/schemas/Test/BasicXmlQueueContract] ;SEND ON CONVERSATION @dialog_handleMESSAGE TYPE [//DEVELOP-ONE.COM/schemas/Test/XmlMessage](@MessageContent) ;-- return dialog_handleSELECT @dialog_handle ;END ;GOCREATE PROCEDURE ReceiveXMLMessage@Timeout int ASBEGINDECLARE @tempTable as TABLE(conversation_handle UNIQUEIDENTIFIER,message_body XML) ;WAITFOR( RECEIVE TOP (1)conversation_handle,message_bodyFROM BasicXmlQueueINTO @tempTable ), TIMEOUT @Timeout;DECLARE @conversation_handle as UNIQUEIDENTIFIER;SELECT TOP (1) @conversation_handle = conversation_handleFROM @tempTable ;IF ( @conversation_handle IS NOT NULL )BEGIN-- remove message from queue without sending an End Of Conversation message.END CONVERSATION @conversation_handle WITH CLEANUP ;END-- return the message bodyselect message_body from @tempTable;END ;GO