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.

networking ❘ 1107<br />

}<br />

{<br />

EventList.Add(ev);<br />

}<br />

}<br />

};<br />

client.GetEventsAsync(DateTime.Today, DateTime.Today.AddMonths(2));<br />

The method OnRegistration() is invoked when the Click event of the Submit Registration button is fi red.<br />

Here again, an asynchronous method is invoked: RegisterAttendeeAsync() to register the attendee.<br />

On completion of this method, NavigationService.Navigate() is used to navigate the user to a<br />

different page.<br />

private void OnRegistration(object sender, RoutedEventArgs e)<br />

{<br />

var client = new RegistrationServiceClient();<br />

CurrentAttendee.EventId = (comboEvents.SelectedItem as Event).Id;<br />

client.RegisterAttendeeCompleted += (sender1, e1) = ><br />

{<br />

if (e1.Error == null)<br />

{<br />

if (e1.Result)<br />

{<br />

NavigationService.Navigate(<br />

new Uri("/Success", UriKind.Relative));<br />

}<br />

else<br />

{<br />

NavigationService.Navigate(<br />

new Uri("/ErrorPage", UriKind.Relative));<br />

}<br />

}<br />

else<br />

{<br />

// display error<br />

}<br />

};<br />

client.RegisterAttendeeAsync(CurrentAttendee);<br />

}<br />

Now the Silverlight application can be started to invoke the WCF Web service.<br />

using WCf data services<br />

Silverlight also gives you access to the client part of WCF Data Services. With this, you can use HTTP<br />

requests to retrieve <strong>and</strong> update data from the Silverlight control without the need to manually defi ne service<br />

methods. Retrieving, updating, <strong>and</strong> adding new data can be done with simple HTTP requests.<br />

WCF Data Services is covered in Chapter 32, “Data Services.”<br />

To offer a service using WCF Data Services for the Silverlight application, a new WCF Data Service item<br />

named EventRegistrationDataService is added to the Web project. The implementation derives from<br />

DataService < EventRegistrationEntities > . The generic parameter for the base class DataService < T ><br />

is the entity data context that was created by the template for the ADO.<strong>NET</strong> Entity Framework. With<br />

config.SetEntitySetAccessRule() , access rules are defi ned to allow read <strong>and</strong> all access to the Events<br />

entity set <strong>and</strong> the Attendees entity set.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!