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

II. MVVM

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).

04_Offline_0104_Offline_0204_Offline_0304_Offline_0504_Offline_06

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.

02_ASPNETDynamicData_01

All samples from part two you can download here

Cheers!!

Wednesday, July 28, 2010

WCF RIA SERVICES v1.0 Samples - part I

In February and March I wrote five good posts with samples about WCF RIA Services Beta. I have refreshed all these samples to work with WCF RIA Services v1.0. I have tested almost all new WCF RIA Services RC1/RC2/v1 features, too. In the near future I’ll write three posts about WCF RIA Services v1.0 features and various extensions. Today I’ll present first part of  it.

I sign changes in my samples: 

  • migration changes & new features
  • migration changes 

Let’s start …

1. BusinessApplicationDemo

If a large number of entities can be returned, consider paging on the client by throttling the results. Now, you can use the ResultLimit property on the QueryAttribute.

01_QueryLimit_01 - mod

Deepesh Mohnani has written a great post how to use server throttling with DomainDataSource.

01_QueryLimit_02 - mod

BTW, there are many changes in DomainDataSource. It no longer blocks loads when another load is pending. SubmitChanges on DomainDataSource no longer automatically reloads data. Filter/sort/group descriptors support binding. There is ICommand support for Load/SubmitChanges/RejectChanges. For more details, read breaking changes.

In the latest RIA Services bits, the total server count of the resulting query is not requested by default for paging scenarios. To explicitly request that the Count method is called, you can set the IncludeTotalCount property on the EntityQuery to true. Deepesh Mohnani has a great post about it here.

01_QueryLimit_05 - mod

DomainDataSource will not request for count in non-paging scenarios. As soon as a page size is specified, DomainDataSource will set the IncludeTotalCount property on the EntityQuery for you. By subscribing to the LoadingData event on the DomainDataSource you can override this behavior.

01_QueryLimit_03 - mod

To reduce the load on the middle tier and database you can use the OutputCacheAttribute attribute for output caching. Now, clients can cache the response because communication between the client and server has been changed from SOAP with binary encoding (only POST) to REST with binary encoding (GET or POST).

02_OutputCache - mod

In the current release, validation rules are enforced by raising events through the INotifyDataErrorInfo interface.

When you create a custom validation class or attribute, you must now pass to the Silverlight application the name or names of the members that failed validation (with the ValidationResult). 

04_SyncValidation_01 - mod 04_SyncValidation_02 - mod 04_SyncValidation_03

BTW, you can write custom authorization rules, just like validation. There’s extensible AuthorizationContext. See CustomAuthorization (ala CustomValidation) attribute written by Nikhil Kothari.

Now, you can very easily perform async validation.  The RIA Services Entity class has the ValidationErrors collection to manipulate the errors at any time. When you call Add, Remove, or Clear on the collection, it translates that into the necessary INotifyDataErrorInfo events. Simply modifying the collection will result in the UI showing the updated errors. Jeff Handley writes about it here. BTW, his async validation example contains the CustomValidation attribute which is different approach than you see below.

03_AsyncValidation_01_B - mod 03_AsyncValidation_02 - mod 03_AsyncValidation_01_A - mod 03_AsyncValidation_03

Some good links about validation

2. ConflictsExamples

Support for LinqToSql classes is now only available in the WCF RIA Services Toolkit

Resolve methods for resolving conflicts in different types of DALs are not  supported in this release of WCF RIA Services.

I have added second version of my example with concurrency conflicts - with Entity Framework.

05_RoundTripping_01 - mod

In the current release, the entire original entity is not sent to the server for concurrency checks any more. Now, you can specify which members are sent to the server by marking them with the RoundtripOriginal attribute. In addition, any members that are marked with the ConcurrencyCheck attribute or the TimeStamp attribute are automatically sent to the server.

05_RoundTripping_02 - mod 05_RoundTripping_03 - mod 05_RoundTripping_04 - mod

3. WindowsAuthentication

4. HttpsExample

5. CrossDomainExample

6. RIAServicesLibrariesDemo

7. MultipleDomainContextsExamples

 

All samples from part one you can download here

Useful links

Start, doc & samples

MIX 10

Channel 9

Silverlight TV

TechEd 10

Silverlight 4 Hands on Labs

Blogs & Sites

Cheers and enjoy!!

Thursday, July 1, 2010

Expression Blend 4: Improvements to Photoshop file import

In Expression Blend 4 some layer effects (Drop Shadow, Inner Shadow, Color Overlay, Outer Glow, Inner Glow, Gradient Overlay, Bevel & Emboss, Satin) can now be merged with their layers.

If a layer effect has been applied to a layer, the Layer effect icon appears next to the layer in the Import Adobe Photoshop File dialog box. A layer effect can be imported either by selecting the Flattened bitmap import option or by merging the layer with other layers.

01_PhotoshopImport_01 01_PhotoshopImport_02

Adam Kinney wrote a great post about importing art from Photoshop and making into Silverlight controls. You should read it!

Sunday, June 20, 2010

Expression Blend 4: Fluid UI - Enhanced FluidMoveBehavior & Layout States

In Blend 4, Fluid Layout has many new tricks. You can now define layout animations between a master list and a detail view and animate things that move between lists. You can also animate the process of items being added to and removed from a ListBox.

An exciting enhancement has been made to the FluidMoveBehavior.

FluidMoveBehaviorMasterDetail
01_FluidMoveBehavior_MasterDetails_01 01_FluidMoveBehavior_MasterDetails_0201_FluidMoveBehavior_MasterDetails_03 - Mod

By using FluidMoveBehavior together with FluidMoveSetTagBehavior, you can animate a transition from a specified starting point, even if that initial location is specified only by a reference to the data that is displayed in your application and may exist in a different scope. Data tagged by FluidMoveSetTagBehavior is available for use with FluidMoveBehavior by using a hidden data store.

FluidMoveBehavior is optimized for two main scenarios: animating from a master list to a detail view and animating list items from one list to another.

FluidMoveBehaviorListToList
02_FluidMoveBehavior_ListToList_0102_FluidMoveBehavior_ListToList_03

In Silverlight 4, a special VisualStateGroup called LayoutStates has been added specifically for animating adding items to and removing items from a ListBox (or custom ItemsControl). You may have a look at my previous post (updated sample you can get from here).

If you also apply a FluidMoveBehavior behavior to the items panel of the ListBox, existing items will smoothly make room for entering new items.

02_FluidMoveBehavior_ListToList_02

Useful links

Thursday, June 10, 2010

My offline extension of DeploymentCatalog

DeploymentCatalog works well in many scenarios. However, when you start  Silverlight out of browser application in offline, cached .xap is not found. So I have extended standard DeploymentCatalog to support offline scenario.

How my offline extension works?

In online out of browser application downloads (or gets from cache) .xap file and saves it  in an additional place - MyDocuments folder. I use trusted mode, so saving works without user interaction and space limit.

When you start out of browser application in offline, .xap file is loaded from MyDocuments folder.

MEF_Offline_Xap_2

I have created DeploymentCatalogWithOffline based on modified DeploymentCatalog sources.  I have changed only implementation of  HandleOpenReadCompleted method (see the screenshot below).

MEF_Offline_Xap_1

You can download complete solution here.

Tuesday, June 8, 2010

Silverlight 4 RTW Samples - part II

I wrote a post with part I of my Silverlight 4 RTW practical summary a  few days ago. Today I’ll continue this topic.

I sign changes in my samples:  

  • API changes or/and new features
  • new sample showing new features

Let’s continue …

9. Out of browser applications - sandboxed (SandboxedOutOfBrowser, MultiTouchPuzzle)

Now you can silent install out of browser application without … browser. You can also launch application without installing.

10. Out of browser applications - trusted (TrustedOutBrowser)

Upon installation of an elevated trust application end user’s will be presented with dialogs shown below.  XAP signing reassures end users of the authenticity of an application’s publisher and that the code has not been tampered with.

Trusted_OOB_WithoutSigningTrusted_OOB_WithSigning

You should experiment with custom window chrome! Your application may look more distinctive!

Silverlight 4 adds the ability to discover when an OOB application’s window is being closed. The Closing event offers the opportunity to cancel this operation in trusted applications.

Trusted_OOB_CustomChrome

11. Implicit styles (ImplicitStylesDemo)

12. CompositeTransform (TransformDemo)

13. MEF (MEF, MEF2, HousePlanner, ExtensibleGrid, SilverlightMEFNavigation)

MEF in final Silverlight 4 has some changes from beta. For example, it contains new DeploymentCatalog.

14. Communication - multicast, authentication & WCF (MulticastChat, ClientHttpStackAuth, WcfTcpBinding, WcfDuplexTcpBinding, VideoChat)

When using a service configured with NetTcp binding, Silverlight does not honor TCP policy served by the server at port 943. This is one of some known WCF issues in Silverlight 4.

WCF_Video_Chat

15. Communication - WCF Data Services (WcfDataServicesDemo, BinaryDataStreamingDemo)

I have added demonstration of server-driven paging and partial entity sets to WcfDataServicesDemo example.

You can work more efficiently by using Visual Studio 2010 Data Sources window !

WCFDataServices_DataSourcesWindow

OData protocol defines a mechanism for accessing binary data separate from an entity to which it belongs. OData service can expose large binary data as a media resource that belongs to a media link entry. The WCF Data Services client for Silverlight can consume a media resource from an OData service as a binary stream.

WCFDataServices_BinaryStream1WCFDataServices_BinaryStream2

16. XML - XPath (XmlDemo)

Silverlight 4 RC/RTW introduces XPath support including XPathNavigator and LINQ to XML extension methods for evaluating XPath expressions on your XElement objects!

XmlXPath

17. New C#4 & platform features (CSharp4, ModifyHTMLbyNET)

18. ViewBox (ViewBoxDemo)

19. Toolkit - ContextMenu & Theming (ThemesDemo)

Silverlight 4 Toolkit April '10 introduces some new features and changes

ThemesDemo example shows new SystemColors theme, using themes at application and page level, custom theme, changing themes at run-time with ContextMenu control.

Toolkit_Themes_App Toolkit_Themes_Menu_Changing Toolkit_Themes_Menu_Xaml Toolkit_Themes_Menu_Code

All samples from part two you can download here

 

Silverlight 4 Tools for Visual Studio 2010 also contains some interesting features. See great video on Silverlight TV!