15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Programming Message Queuing ❘ 1367<br />

try<br />

{<br />

if (!MessageQueue.Exists(@".\Private$\MyPrivateQueue"))<br />

{<br />

MessageQueue.Create(@".\Private$\MyPrivateQueue");<br />

}<br />

var queue = new MessageQueue(@".\Private$\MyPrivateQueue");<br />

}<br />

}<br />

}<br />

queue.Send("Sample Message", "Label");<br />

}<br />

catch (MessageQueueException ex)<br />

{<br />

Console.WriteLine(ex.Message);<br />

}<br />

code snippet SendMessage/Program.cs<br />

Figure 46-7 shows the Computer Management admin tool where you can see the message that arrived in<br />

the queue.<br />

figure 46-7<br />

By opening the message <strong>and</strong> selecting the Body tab (see<br />

Figure 46-8) of the dialog box, you can see that the message<br />

was formatted using XML. Determining how the message is<br />

formatted is the function of the formatter that’s associated<br />

with the message queue.<br />

Message formatter<br />

The format in which messages are transferred to the queue<br />

depends on the formatter. The MessageQueue class has<br />

a Formatter property through which a formatter can be<br />

assigned. The default formatter, XmlMessageFormatter, will<br />

format the message in XML syntax as shown in the previous<br />

example.<br />

figure 46-8<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!