mvvm & wcf ria services: an architectural story

35
SL, MVVM & RIA services An architectural story Kevin Dockx TC/TPL RealDolmen

Upload: microsoft-developer-network-msdn-belgium-and-luxembourg

Post on 19-Jun-2015

2.298 views

Category:

Technology


0 download

DESCRIPTION

At the start of each project, you’ll have to lay out your solution architecture - and it’s very important to “get this right”. Silverlight, MVVM & WCF RIA Services work nicely together, but as with each architecture, the best solution depends on your application requirements. What are your options in this case? What are the pitfalls? How can you tie these technologies together to provide you with a solid foundation for your projects? This is an in-depth session, based on real-life experience.

TRANSCRIPT

Page 1: MVVM & WCF RIA Services: an architectural story

SL, MVVM & RIA servicesAn architectural story

Kevin DockxTC/TPLRealDolmen

Page 2: MVVM & WCF RIA Services: an architectural story

Who am I?

Kevin DockxTechnical consultant & solution manager rich applications @RealDolmen

• e-mail: [email protected] • blog: http://blog.kevindockx.com/ • twitter: @kevindockx

Page 3: MVVM & WCF RIA Services: an architectural story

Who am I?

Author of the Silverlight 5 Data and Services Cookbook

• 650 pages of recipes for creating rich, LOB apps with Silverlight• Focus on data & services• Including, but not limited to MVVM, REST&SOAP,

WCF RIA Services, Windows Phone 7, …

Page 4: MVVM & WCF RIA Services: an architectural story

Session Contents• wcf ria services 101• wcf ria services: the problem• getting ready for an enterprise-level app: a cleaner project structure & better

separation• getting ready for an enterprise-level app: more separation: the DAL• getting ready for an enterprise-level app: limit points of exposure• using a custom DomainServiceFactory for authentication• there’s more… a lot more

• conclusion and q&a

Page 5: MVVM & WCF RIA Services: an architectural story

Shoutouts!Rule #1: most of what you want has already been thought off. Get inspired by what’s available, and share what you know.MVVM Light – Laurent Bugnion• http://www.galasoft.ch/mvvm/

RIA Contrib• http://riaservicescontrib.codeplex.com/

Sandrino Di Mattia• http://sandrinodimattia.net/Blog/

Page 6: MVVM & WCF RIA Services: an architectural story

WCF RIA Services 101

Page 7: MVVM & WCF RIA Services: an architectural story

WCF RIA Services 101

“simplifies development of n-tier solutions for RIA”

makes app logic written on server available on client

• entities, relationships, validation, business rules, authentication, authorization, …

Page 8: MVVM & WCF RIA Services: an architectural story

WCF RIA Services 101

On the server• Domain Services

• WCF Service that encapsulates business logic• Exposes a set of related operations• CRUD, Invoke, Named Update

Page 9: MVVM & WCF RIA Services: an architectural story

WCF RIA Services 101

On the client• The DomainContext (“the database server”)• Move entities between domainservice & entitysets• Through WCF ChannelFactory

• The EntityContainer (“the database”)• Stores the EntitySets

• The EntitySet (“the table”)• Contains Entities of a specific type

Page 10: MVVM & WCF RIA Services: an architectural story

DemoSay hello to NICO

Page 11: MVVM & WCF RIA Services: an architectural story

The problem

Marketed for RAD, templates aimed at RAD

Not good enough for Enterprise-grade applications

• The DAL = the Service host? • Web host & Service host = the same?• Friendly service names? • What about separation?

Page 12: MVVM & WCF RIA Services: an architectural story

Clean project, better separation

Page 13: MVVM & WCF RIA Services: an architectural story

Clean project, better separation

Default RIA template

• silverlight app & web app• web app contains SL app, domain services & entity model• little to no separation• little to no reusability• it’s easy, it’s fast, it’s very much not suited for enterprise-grade applications

Page 14: MVVM & WCF RIA Services: an architectural story

Clean project, better separation

RIA Services Class Library template

• reuse of domain services across different SL projects• yet: services still hosted in the same host as the SL app• no separation of DAL• unfriendly, confusing project names (RIAServicesLibrary &

RIAServicesLibrary.Web)

Page 15: MVVM & WCF RIA Services: an architectural story

Clean project, better separation

What we want to end up with:

• cleaner, better assembly/namespace naming• more in line with MVVM naming (Model = in .Model NS)• friendly service names• separate web host & service host for higher reuse / separation / reliability

Page 16: MVVM & WCF RIA Services: an architectural story

DemoBetter structure & separation (naming, hosts)

Page 17: MVVM & WCF RIA Services: an architectural story

More separation: the DAL

Page 18: MVVM & WCF RIA Services: an architectural story

More separation: the DAL

What we want to end up with:

• Higher degree of separation• Allows reuse of your DAL in other projects

Page 19: MVVM & WCF RIA Services: an architectural story

DemoSeparating the DAL

Page 20: MVVM & WCF RIA Services: an architectural story

More separation: the DAL

Not perfect though…• Metadata is still in the same assembly as the EM• Same NS: implementation is divided over 2 separate assemblies, not completely

decoupled

Page 21: MVVM & WCF RIA Services: an architectural story

Limit points of exposure

Page 22: MVVM & WCF RIA Services: an architectural story

Limit points of exposure

Regular Silverlight app

• web host + service host on the same physical machine, in the same website• access to webserver = access to database (aka: A Bad Thing)

Page 23: MVVM & WCF RIA Services: an architectural story

Limit points of exposure

Our current app

• separate tiers on separate physical machines• however: Silverlight app requires access to the service tier => needs to be

exposed to the internet

Page 24: MVVM & WCF RIA Services: an architectural story

Limit points of exposure

What we want to end up with:

• single point of exposure: only the presentation tier is exposed to the internet

Page 25: MVVM & WCF RIA Services: an architectural story

Limit points of exposure

Solution: application request routing & url rewrites

What we’re going to do:• through ARR, we’ll use IIS as a reverse proxy• the reverse proxy will retrieve resources from one or more servers, which are

returned to the client as though they originated from the reverse proxy itself.• in our case: it will retrieve data from our service host as though it originated

from the web host

Page 26: MVVM & WCF RIA Services: an architectural story

DemoLimit points of exposure (arr)

Page 27: MVVM & WCF RIA Services: an architectural story

Authentication: typed user

Page 28: MVVM & WCF RIA Services: an architectural story

Authentication: typed user

Often, the authenticated user is required on both client and serverWe’ve got: HttpContext.Current.User.Identity on the server

• System.Security.Principal.IIdentity• properties: Name, IsAuthenticated

We would like: a typed user, with extra properties, property collections and/or methods

Page 29: MVVM & WCF RIA Services: an architectural story

DemoTyped user (custom domain service factory)

Page 30: MVVM & WCF RIA Services: an architectural story

More, please?

Page 31: MVVM & WCF RIA Services: an architectural story

There’s more… a lot more

Error handling• override OnError, plug in a handling/logging component

Server-side paging & MVVM• use the DomainCollectionView (RIA Services Toolkit)

Server-side paging & store queries• DCV + totalCount output parameter on operation signature

Page 32: MVVM & WCF RIA Services: an architectural story

Session Summary

WCF RIA Services is powerful & extensible

Look beyond the marketing talk, and find an enterprise-grade framework

The future is an API

Page 33: MVVM & WCF RIA Services: an architectural story

Q&A

Page 34: MVVM & WCF RIA Services: an architectural story

Be what’s next• Find everything here

http://aka.ms/mbl-tech• Visual Studio Developer Preview Downloads

http://aka.ms/mbl-tech/devprev• MSDN HTML5 Developer Center

http://aka.ms/mbl-tech/html5

Page 35: MVVM & WCF RIA Services: an architectural story

© 2012 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.