mvvm & wcf ria services: an architectural story
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
SL, MVVM & RIA servicesAn architectural story
Kevin DockxTC/TPLRealDolmen
Who am I?
Kevin DockxTechnical consultant & solution manager rich applications @RealDolmen
• e-mail: [email protected] • blog: http://blog.kevindockx.com/ • twitter: @kevindockx
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, …
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
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/
WCF RIA Services 101
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, …
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
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
DemoSay hello to NICO
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?
Clean project, better separation
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
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)
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
DemoBetter structure & separation (naming, hosts)
More separation: the DAL
More separation: the DAL
What we want to end up with:
• Higher degree of separation• Allows reuse of your DAL in other projects
DemoSeparating the DAL
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
Limit points of exposure
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)
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
Limit points of exposure
What we want to end up with:
• single point of exposure: only the presentation tier is exposed to the internet
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
DemoLimit points of exposure (arr)
Authentication: typed user
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
DemoTyped user (custom domain service factory)
More, please?
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
Session Summary
WCF RIA Services is powerful & extensible
Look beyond the marketing talk, and find an enterprise-grade framework
The future is an API
Q&A
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
© 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.