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.

1104 ❘ ChaPTer 38 silverliGht<br />

}<br />

}<br />

public bool RegisterAttendee(Attendee attendee)<br />

{<br />

using (EventRegistrationEntities data =<br />

new EventRegistrationEntities())<br />

{<br />

if ((from rc in data.RegistrationCodes<br />

where rc.RegistrationCode1 == attendee.RegistrationCode<br />

select rc).Count() < 1)<br />

{<br />

return false;<br />

}<br />

else<br />

{<br />

data.Attendees.AddObject(attendee);<br />

if (data.SaveChanges() == 1)<br />

{<br />

return true;<br />

}<br />

else<br />

{<br />

return false;<br />

}<br />

}<br />

}<br />

}<br />

code snippet SilverlightDemos.Web/RegistrationService.svc.cs<br />

The default BasicHttpBinding that is used with WCF hosting in the ASP.<strong>NET</strong> web application is okay for<br />

use by Silverlight clients, <strong>and</strong> thus doesn ’ t need any confi guration. The only confi guration needed to make it<br />

possible to add a service reference from Visual Studio is to allow the publishing of metadata with the HTTP<br />

GET protocol as shown.<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

code snippet SilverlightDemos.Web/Web.config<br />

Starting with Silverlight 3, it is possible to confi gure a binary encoding with the HTTP<br />

transport. Silverlight 3 implements this encoding to allow for better performance. This<br />

custom binding is used by default if you add a Silverlight-enabled WCF Service.<br />

Calling WCf services<br />

Before calling the service, a UI needs to be created. In the same Silverlight project as before, where the<br />

animation was done, the Home.xaml page is changed to include ComboBox <strong>and</strong> TextBox controls to allow<br />

entering information for an event <strong>and</strong> registering for the event. The design view of the application is shown<br />

in Figure 38 - 5.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!