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.

1382 ❘ ChaPTer 46 messAGe QueuinG<br />

CourseOrderService.CourseOrderAdded += (sender, e) =<br />

{<br />

courseOrders.Add(e.CourseOrder);<br />

buttonProcessOrder.IsEnabled = true;<br />

}<br />

var host = new ServiceHost(typeof(CourseOrderService));<br />

try<br />

{<br />

host.Open();<br />

}<br />

catch (Exception ex)<br />

{<br />

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

}<br />

}<br />

this.DataContext = courseOrders;<br />

code snippet CourseOrderReceiver/CourseOrderReceiverWindow.xaml.cs<br />

The WPF elements in the XAML code now make use of data binding. The ListBox is bound to the data<br />

context, <strong>and</strong> the single - item controls are bound to properties of the current item of the data context:<br />

< ListBox Grid.Row="1" x:Name="listOrders" ItemsSource="{Binding}"<br />

IsSynchronizedWithCurrentItem="true" / ><br />

< !-- ... -- ><br />

< TextBox x:Name="textCourse" Grid.Row="0" Grid.Column="1"<br />

Text="{Binding Path=Course.Title}" / ><br />

< TextBox x:Name="textCompany" Grid.Row="1" Grid.Column="1"<br />

Text="{Binding Path=Customer.Company}" / ><br />

< TextBox x:Name="textContact" Grid.Row="2" Grid.Column="1"<br />

Text="{Binding Path=Customer.Contact}" / ><br />

code snippet CourseOrderReceiver/CourseOrderReceiverWindow.xaml<br />

The application confi guration fi le defi nes the netMsmqBinding . For reliable messaging, transactional queues<br />

are required. To receive <strong>and</strong> send messages to non - transactional queues, the exactlyOnce property must be<br />

set to false .<br />

netMsmqBinding is the binding to be used if both the receiver <strong>and</strong> the sender<br />

application are WCF applications. If one of these applications is using the System<br />

.Messaging API to send or receive messages, or is an older COM application, you can<br />

use msmqIntegrationBinding.<br />

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

< configuration ><br />

< system.serviceModel ><br />

< bindings ><br />

< netMsmqBinding ><br />

< binding name="NonTransactionalQueueBinding" exactlyOnce="false" ><br />

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

< /binding ><br />

< /netMsmqBinding ><br />

< /bindings ><br />

< services ><br />

< service name="Wrox.ProCSharp.Messaging.CourseOrderService" ><br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!