<% If Request("DontFrame")<>1 Then Response.Redirect "/iissamples/sdk/asp/docs/SampFram.asp?ovfile=/iishelp/iis/htm/sdk/samp6qzp.asp&srcfile=Queuing/TransactedDelivery" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
MSMQ message delivery can be wrapped as an MTS transaction, just as any other ASP script. This sample illustrates how to open a transacted queue, and send a simple message to it, all within a transaction wrapper.</p>
<p>
Like any other transacted Web page, this sample starts with the @TRANSACTION=REQUIRED directive. All actions taken by the script, such as an MSMQ message transmission, will be grouped together as one single, indivisible transaction that either is completed or aborted in its entirety. </p>
<p>
This example then creates an instance of the <b>MSMQQueueInfo</b> object, which will be used as a template for the actual queue object instances. <b>MSMQQueueInfo</b> contains a number of properties that can be used to configure the queue instances it will create, but in this sample, only the <b>PathName</b> property is set. <b>PathName</b> specifies the MSMQ pathname of the queue, and is given in the general form <i>MachineName\QueueName</i>. Note that in this example, the <i>MachineName</i> part of the MSMQ pathname is a period (.), which indicates that the queue is located on the local computer.</p>
<p>
The <b>MSMQQueueInfo.Open</b> method is used to create an instance of the actual queue object, <b>MSMQQueue</b>, and the variable <i>Queue</i> is set to refer to the new queue instance. </p>
<p>
At this point, having gained access to the IIS_SDK_TRANSACTED queue, this sample now creates a new message object by instantiating <b>MSMQMessage</b>. The reference to the instance, <i>Msg</i>, is used to set the description and content of the message using the <b>Label</b> and <b>Body</b> properties. The <b>Delivery</b> property, which indicates whether express or recoverable delivery is used, is also set at this time. For this demonstration, it has been set to indicate that MSMQ is to use recoverable delivery. </p>
<p>
With the message complete and the queue configured, the script is ready to send the message. The <b>MSMQMessage.Send</b> method is called to send the message to the queue pointed to by the reference <i>Queue</i>, and the queue is closed with the <b>Close</b> method. If the script, and hence the transaction, completed without error, the <b>OnTransactionCommit</b> method is executed, and you are notified of the success. Any errors encountered in the execution of the sample will cause <b>OnTransactionAbort</b> to be called instead. </p>
<p>
<b>Note</b> This sample requires that MSMQ be installed on your host machine. It also requires, prior to running this sample for the first time, that you start MSMQ Explorer and create a new transacted queue named IIS_SDK_TRANSACTED. MSMQ Explorer can also be used after the sample is run so that you can examine the results of the script's execution.</p>