15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1384 ❘ ChaPTer 46 messAGe QueuinG<br />

}<br />

{<br />

}<br />

MessageBox.Show(ex.Message, "Course Order Error",<br />

MessageBoxButton.OK, MessageBoxImage.Error);<br />

code snippet CourseOrderSender/CourseOrderWindow.xaml.cs<br />

The application confi guration fi le defi nes the client part of the WCF connection. Again, the<br />

netMsmqBinding is used:<br />

< xml version="1.0" encoding="utf-8" ><br />

< configuration ><br />

< system.serviceModel ><br />

< bindings ><br />

< netMsmqBinding ><br />

< binding name="nonTransactionalQueueBinding"<br />

exactlyOnce="false" ><br />

< security mode="None" / ><br />

< /binding ><br />

< /netMsmqBinding ><br />

< /bindings ><br />

< client ><br />

< endpoint address="net.msmq://localhost/private/courseorder"<br />

binding="netMsmqBinding"<br />

bindingConfiguration="nonTransactionalQueueBinding"<br />

contract="Wrox.ProCSharp.Messaging.ICourseOrderService"<br />

name="queueEndpoint" / ><br />

< /client ><br />

< /system.serviceModel ><br />

< /configuration ><br />

code snippet CourseOrderSender/app.config<br />

When you start the application now, it works in a similar way as before. There is no longer a need to<br />

use classes of the System.Messaging namespace to send <strong>and</strong> receive messages. Instead, you write the<br />

application in a similar way as using TCP or HTTP channels with WCF.<br />

However, to create message queues <strong>and</strong> to purge messages, you still need the MessageQueue class. WCF is<br />

only an abstraction to send <strong>and</strong> receive messages.<br />

If you need to have a System.Messaging application to communicate with a WCF<br />

application, you can do so by using the msmqIntegrationBinding instead of the<br />

netMsmqBinding. This binding uses the message format that is used with COM <strong>and</strong><br />

System.Messaging.<br />

message queue insTallaTion<br />

Message queues can be created with the MessageQueue.Create() method. However, the user running an<br />

application usually doesn ’ t have the administrative privileges that are required to create message queues.<br />

Usually, message queues are created with an installation program, using the class<br />

MessageQueueInstaller . If an installer class is part of an application, the comm<strong>and</strong> - line utility<br />

installutil.exe (or a Windows Installation Package) invokes the Install() method of the installer.<br />

Visual Studio has special support for using the MessageQueueInstaller with Windows Forms<br />

applications. If a MessageQueue component is dropped from the toolbox onto the form, the smart tag of the<br />

component allows you to add an installer with the menu entry Add Installer. The MessageQueueInstaller<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!