With the release of the RIA Services Release Candidate, it was time to refresh the ContosoSales application that was first shown in the PDC keynote. Let’s take a look at the changes made to move to the new release.
The steps below are based on having downloaded the styled ContosoSales application from PDC. If you want to cut to the chase and download the new version of the solution, you can grab it here for use with the RIA Services RC bits.
Changes to References
In trying to migrate the application, the first thing we notice is that the namespaces have changed (again, and for the last time).
With the PDC09 release, project had the following assemblies referenced for RIA Services:
- Silverlight Project:
- System.Windows.Controls.Ria
- System.Windows.Ria
- ASP.NET Project:
- System.Web.DomainServices
- System.Web.DomainServices.EntityFramework
- System.Web.Ria
With the Release Candidate (Mix10) release, we now have:
- Silverlight Project:
- System.ServiceModel.DomainServices.Client
- System.ServiceModel.DomainServices.Client.Web
- System.Windows.Controls.DomainServices
- System.ServiceModel.Web.Extensions
(this isn’t a RIA Services assembly, but we now need this reference)
- ASP.NET Project:
- System.ServiceModel.DomainServices.EntityFramework
- System.ServiceModel.DomainServices.Hosting
- System.ServiceModel.DomainServices.Server
Consume the New References
The next change to address is the web.config file where assembly and namespace names were referenced.
Change:
<system.web>
<httpModules>
<add name="DomainServiceModule"
type="System.Web.Ria.Services.DomainServiceHttpModule, System.Web.Ria, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="DomainServiceModule"
preCondition="managedHandler"
type="System.Web.Ria.Services.DomainServiceHttpModule, System.Web.Ria, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>
</system.webServer>
To:
<system.web>
<httpModules>
<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="DomainServiceModule" preCondition="managedHandler"
type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</modules>
</system.webServer>
This changed “System.Web.Ria.Services.DomainServiceHttpModule, System.Web.Ria” to “System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting” in two places.
The next step is to change the namespaces referenced by the DomainService and metadata files. Open up ContactService.metadata.cs and work through the changes needed for that file.
- Remove the using statement for System.Web.DomainServices
- Add a using statement for System.ServiceModel.DomainServices.Server
Open up ContactService.cs and make the following changes:
- Remove the using statement for System.Web.DomainServices.Providers
- Remove the using statement for System.Web.Ria
- Add a using statement for System.ServiceModel.DomainServices.Hosting
- Add a using statement for System.ServiceModel.DomainServices.EntityFramework
We also need to change the UpdateContact code from:
public void UpdateContact(Contact currentContact)
{
if ((currentContact.EntityState == EntityState.Detached))
{
this.ObjectContext.AttachAsModified(currentContact, this.ChangeSet.GetOriginal(currentContact));
}
}
To:
public void UpdateContact(Contact currentContact)
{
this.ObjectContext.Contacts.AttachAsModified(currentContact, this.ChangeSet.GetOriginal(currentContact));
}
Let’s flip over to the Silverlight project, open up the Views\Home.xaml file and make some changes there. Let’s start off changing the xmlns:riaControls from "clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Ria" to "clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
Build and Run
With that, the ContosoSales application is running again, using the WCF RIA Services Release Candidate release. Let’s make one more change before we call it finished though.
DomainDataSource ICommand Support
You might recall that when Scott Hanselman was building this app onstage at PDC, he had to dive into the code-behind for the screen and wire up the Save button. Well, with DomainDataSource’s newly added support for ICommand, you can now bind the button to a command.
The first thing we want to do for this is to remove the code-behind code for the save button’s click handler. Delete the following code:
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
this.storeDomainDataSource.SubmitChanges();
}
And now in the XAML, change the save button from:
<Button Content="SAVE" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top"
Margin="182,0,0,0" Name="SaveButton" Width="114" Height="36" FontSize="18"
Click="SaveButton_Click" />
To:
<Button Content="SAVE" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top"
Margin="182,0,0,0" Name="SaveButton" Width="114" Height="36" FontSize="18"
Command="{Binding ElementName=storeDomainDataSource, Path=SubmitChangesCommand}" />
Using the WCF RIA Services Release Candidate
Hopefully this post helps you get your own applications up and running with the release candidate. Here are some links to help you really get going with the new release:
- RIA Services “Home Page” with download links – http://silverlight.net/riaservices
- RC Breaking Changes Document
- The updated version of this ContosoSales application
(with a couple of extra features for you to discover)