Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hello WCF RIA Services An introduction to RIA Services Gill Cleeren Microsoft Regional Director Silverlight MVP Ordina Belgium.

Similar presentations


Presentation on theme: "Hello WCF RIA Services An introduction to RIA Services Gill Cleeren Microsoft Regional Director Silverlight MVP Ordina Belgium."— Presentation transcript:

1

2 Hello WCF RIA Services An introduction to RIA Services Gill Cleeren Microsoft Regional Director Silverlight MVP Ordina Belgium

3 Glad to meet you... Gill Cleeren Microsoft Regional Director Silverlight MVP Telerik Insider & MVP.NET Architect @Ordina (www.ordina.be)www.ordina.be Speaker (TechDays BE-NL-UK-SE-CH..., TechEd Berlin, DevDays, NDC Norway, Spring Conference UK, SQL Server Saturday Switzerland...) Visug user group lead (www.visug.be)www.visug.be Author (Silverlight 4 Data and services cookbook) www.snowball.be - gill@snowball.be - @gillcleeren www.snowball.begill@snowball.be

4 Agenda Part 1: Introduction to WCF RIA Services Part 2: The basics of RIA Services Part 3: Concepts explained Part 4: What about MVVM? Part 5: Let’s validate!

5 PART 1: INTRODUCTION TO WCF RIA SERVICES

6 Web service Trust Boundary The situation of the problem…

7 What is WCF RIA services exactly then? Framework: WCF RIA Services provide end-to-end use of data Retrieved by DAL of choice, shaped in BLL, annoted for validation Data and metadata can flow over tiers through controlled set of operations Tools: build multiple tiers together Code is generated on the client Services: common services such as authentication can be reused Based on ASP.NET foundation Framework, tools and services with prescriptive pattern for n-tier applications

8 Why WCF RIA Services? Less plumbing code to write Prescriptive approach for working with data on the client side Makes working with WCF easier, hides details Makes using LINQ possible in n-tier scenarios Client side framework for service calls, validation and security

9 End-to-end view of an application: – Framework – Tooling – Services Prescriptive approach to app logic DAL-neutral and targets multiple presentation technologies Make RIA development as productive as ASP.NET development.NET on server and on client Important design principles

10 Being neutral AppLogic Databases ADO.NET, ORMs (LTS, EF, …) Lists/Objects Repository (NHibernate, …) Services REST/SOAP (Azure, …).NET Clients Silverlight, WPF (hopefully phone) Standards Clients JavaScript Server Rendering HTML, Sitemaps Services SOAP, XML, JSON, OData Unit Test Code

11 How do I get WCF RIA Services? If you have Silverlight tools installed, you have RIA Services already Additional download: RIA Services Toolkit – Adds support for other endpoint types (SOAP, JSON) – ASP.NET support for consuming domain service in process WCF RIA Services SP1 – We’ll look at this later!

12 PART 2: THE BASICS OF WCF RIA SERVICES

13 The Dev Process: Server-Side 1 2 3 4 Create Business Application Create Entity Model Create Domain Service Add/generate queries 5 Modify Metadata

14 DEMO Creating the server-side

15 The Dev Process: Client-Side Use Data Sources window 2 Drag on the interface 3 1 Generate DomainDataSource Success! 4 Note that this is just one way of using RIA services

16 DEMO Creating the client-side

17 PART 3: CONCEPTS EXPLAINED

18 Concepts of RIA Services Code generation Domain Data source Validation Meta data Querying Shared code Authentication WCF RIA SERVICES Domain Context

19 Server-side Domain Service Metadata Classes Validation Attributes Security Attributes Shared Code

20 Use query operations to read data Inside the service, we can query data – Query operations return object, IEnumerable or IQueryable IQueryable and LINQ provider are required if we want to use deferred execution – Based on convention (GetXXX, RetrieveXXX…) If convention isn’t possible, use Query attribute Other attributes exist: – IsComposable=false when returning single entity – ResultLimit to constrain maximum items returned to client

21 Let’s defer things The use of IQueryable : Deferred Execution – RIA Services serializes the expression tree from the client the server – LINQ operations specified by the expression tree are executed on the server – When the underlying provider supports it (i.e. Entity Framework and LINQ to SQL), deferred execution goes all the way to the DB

22 Querying Relations What if we want to return related entities in one go? – Load all Hotels for a City – Step 1 (Entity Framework) ObjectContext.Cities.Include(“Hotels”) – Step 2: Entity metadata type needs [Include] attribute on related property

23 Conventions can help us! RIA Services uses naming conventions in domain service to identify methods – Insert: InsertXXX, AddXXX, CreateXXX – Update: UpdateXXX, ModifyXXX, ChangeXXX – Delete: DeleteXXX, RemoveXXX – Where XXX is an entity type name If we want Dutch code (yes some people do that…), we can use Attributes – Insert, Update, Delete attributes

24 Metadata or buddy classes Define a partial class for the entity type Define a nested metadata class inside the entity type – Not required, but convention – “Buddy class” Add a MetadataType attribute on the entity partial class to tie in the metadata type Add attributes to properties on the metadata type that match the entity properties Those attributes show up on the client entity type or influence entity transmission – Validation – Include – Exclude – Composition

25 Client-side Domain Context Entity QueryEntity Load Operation Submit Operation

26 Client-side generated entities On the client, entities get generated (code-generation) – Entity Framework or LINQ to SQL entities supported automatically – POCOs must follow certain conventions Must have a [Key] property Relation properties must have an [Association] attribute to indicate the related property type’s key fields Need [Include] attribute on properties to child entity collections or single entities to have them serialized

27 Loading Data on the Client Option 1: what you CAN do: the DomainDataSource – Allow you to execute a DomainContext method to query data Including updates Happens async – Drag/drop data binding is VS 2010  generates XAML DomainDataSource and Grid (we’ve seen this in the demo) – Supports parameterized queries – Supports sorting, grouping, filtering, paging  Not a good fit with MVVM Puts query “logic” into the view

28 Loading Data on Client Option 2: What you SHOULD do: DomainContext.Load() – Pass an EntityQuery – Can modify the expression tree on client if target method in DomainService returns IQueryable – Executes asynchronously – Bind to entity collection for automatic update via INotifyCollectionChanged – Pass async callback to be notified and work with results or handle errors yourself – Can work with returned LoadOperation for async notification as well

29 Update Operations Implicit unit of work: – Entity changes are cached in the client DomainContext until SubmitChanges called  Contains an EntityContainer for each entity type that tracks changes Sent as a batch to the service – Including original version for optimistic concurrency Service executes batch, calling Insert, Update, and Delete methods with one entity per method call

30 Security Authentication Roles User profile Declarative: class / method-level Integrated into Query / Submit processing All based on ASP.NET infrastructure

31 What is added with SP1? Cloud Ready Complex Type Support Shared Entities T4 Templates Domain Collection View

32 DEEP-DIVE DEMO

33 PART 4: WHAT ABOUT MVVM?

34 RIA Services and MVVM == BFF

35 MVVM DEMO

36 PART 5: VALIDATION WITH WCF RIA SERVICES

37 Validation in Silverlight Validation in Silverlight is based on the concept of data binding Several options exist: – IDataErrorInfo – INotifyDataErrorInfo INotifyDataErrorInfo supports async validation – When we set a value, it may be OK client-side but not server-side – An event is raised if server-side validation fails – Silverlight watches for this event being raised RIA Services Entity base class provides the implementation

38 INotifyDataErrorInfo interface public interface INotifyDataErrorInfo { bool HasErrors { get; } event EventHandler ErrorsChanged; IEnumerable GetErrors(string propertyName); }

39 RIA Services Validation Options We have 3 options: 1. DataAnnotations attributes 2. Server update method exceptions 3. Client async service method calls

40 Data Annotations Attributes Live in System.ComponentModel.DataAnnotations namespace – Also used by ASP.NET MVC and Dynamic Data Contains a few standard attributes: – [Required] – [Range] – [RegEx] – [StringLength] And then there’s the Custom one… – [CustomValidation] – Define static method with appropriate signature: public static ValidationResult ValidateCityName(string newCityName, ValidationContext context)

41 Data Annotations how-to WCF RIA Services will automatically evaluate data annotation attributes on both client and server side For Entity Framework generated types on server, define metadata class and put attributes on its properties Client generated entities contain same attributes CustomValidation methods must be put in a.shared.cs file so they get copied to the client side

42 Server Validation Exceptions Some things have to be evaluated on the server – Can wait until update batch is submitted to evaluate validation rules server side – Throw ValidationException from insert, update, or delete method – RIA Services automatically associates the error with the individual entity and hooks into the validation client side – Will still be raised as an exception from the SubmitChanges method, must handle – Can also inspect properties of the SubmitOperation EntitiesInError collection

43 Client Async Calls Expose [Invoke] methods on domain service Call method with value to be changed, get back result Set validation errors manually – Entity.ValidationErrors.Add

44 VALIDATION DEMO

45 Summary RIA services opens up oppurtunity to build n- tier apps with ease Built on power of WCF Key concepts explained Works in combination with MVVM Supports several validation types

46 Q&(HOPEFULLY)A

47 THANKS!

48 Hello WCF RIA Services Gill Cleeren Microsoft Regional Director Silverlight MVP Ordina Belgium

49 © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Partner logo to go here


Download ppt "Hello WCF RIA Services An introduction to RIA Services Gill Cleeren Microsoft Regional Director Silverlight MVP Ordina Belgium."

Similar presentations


Ads by Google