Thursday, August 5, 2010

WCF RIA SERVICES v1.0 - Extra Cool Samples !

Today I’ll write about very interesting scenarios with WCF RIA Services. Read this post!

I. NHibernate

You can quite easily use NHibernate as your DAL. Look at the latest NHibernate Sample from WCF RIA Services Code Gallery with related entities! I have made a simpler example without associations (look below).

01_NHibernate_01 01_NHibernate_02 01_NHibernate_0301_NHibernate_0401_NHibernate_05


Nikhil Kothari at MIX 10’ has shown how to use WCF RIA Services with MVVM pattern (domain context as a member of view model). Deepesh Mohnani at TechEd 2010 has presented a great WCF RIA Services application with MVVM (for lazy developers: view model inherited from Entity). 

III. Lookups (ComboBoxDataSource)

Kyle McClellan from WCF RIA Services team has added to code gallery a cool example with an extension to support lookups - ComboBoxDataSource. He has implemented cascading ComboBoxes scenario (lookup data sources with parameters like DomainDataSource filters). You can also see how to use lookups for Entity associations. Read about details of the solution here and here.

I have built a simpler example with one ComboBox for Entity association (look below).

02_Lookup_01 02_Lookup_03 02_Lookup_04

IV. T4

Early versions of WCF RIA Services Contrib had contained T4 templates for generating domain services and metadata classes (replacement WCF RIA Services wizard). Now T4 templates have been made obsolete - WCF RIA Services V2 itself is supposed to start using T4 templates

V. Fluent metadata !

The standard approach of defining WCF RIA Services entity metadata is based on attributes. But some developers don't like attributes and ask for a fluent interface instead. Nikhil Kothari has created Fluent API for .NET RIA Services Metadata for July 09’ version. LINQ expressions are mapped to WCF RIA Services. attributes. You can also define your own custom rules (mapped as standard CustomValidation attributte). Nikhil will add these extensions to RIA Services Essentials at codeplex.

Some people and I have migrated these extensions to work with WCF RIA Services V1. I have made example application with fluent metadata (look below).

03_FluentMetadata_02 03_FluentMetadata_03 03_FluentMetadata_01

VI. Offline

Nikhil Kothari at TechEd 09’ South Africa has presented an offline synchronization example (he’ll plan to public update for it).

WCF RIA Services DomainContext is good for offline scenario. WCF RIA Services Contrib contains an extension to serialize it to Isolated Storage and deserialize from.   

I have tried to migrate Nikhil Kothari’s solution to work with WCF RIA services V1 and it … works! I have built simple application using this mechanism (look below).


You can download my examples (NHibernate, Lookup, Fluent metadata, Offline) here:

Monday, August 2, 2010

WCF RIA SERVICES v1.0 Samples - part II

I showed part I of my WCF RIA Services v1.0 samples a  few days ago. Today I’ll continue this topic.

I sign changes in my samples:  

  • migration changes & new features
  • migration changes

Let’s continue …

08. RelatedEntitiesDemo

09. CompositionExample

10. InheritanceExample

The workaround for EF described here no longer needed. I have added modifying entities to my sample application.

11. PresentationModelDemo

12. WcfDemo

WpfClientApp (and SOAP communication) moved to new EndpointsDemo example.

13. EndpointsDemo

By default, only the Binary endpoint is enabled for domain services without additional configuration. You can easily enable another endpoint (ODATA, SOAP, JSON or custom) by registering an endpoint factory in the Web.config file as shown below.

01_Endpoints_01 - mod

The ODATA endpoint has very limited support in V1. There is no Update or LINQ query support. Deepesh Mohnani has a great post about WCF RIA Services endpoints.

Clients in my example:

  • BusinessApplicationDemo (Silverlight, default endpoint)
  • BusinessApplicationDemo.Web (AJAX, JSON)
  • WpfClientApp (WPF, SOAP)
  • ODataClientApp (Silverlight, ODATA)

Below is an example query method in the Ajax client.

01_Endpoints_02 - mod 01_Endpoints_03

14. ASPNetDynamicDataExample

I have used a new project template called ASP.NET Dynamic Data Domain Service Web Application in WCF RIA Services Toolkit.


All samples from part two you can download here