• @deepeshm

    Silverlight TV Episode 26: Exposing SOAP, jSON and OData Endpoints from RIA Services


    I recently recorded a Silverlight TV episode where I demoed configuring a RIA Services DomainService to expose SOAP, JSon and OData endpoints. The video went online earlier today and it can be found here.

    Oh and be sure to check out for Silverlight TV Episode 28. It’s going to be awesome!! Stay Tuned!



    Why would you expose other endpoints?

    As you all are aware, RIA Services has a great story OM and  tooling story for Silverlight.What if you want a mobile application talking to a domain service or an Ajax application? There could be various different reasons why one would want to expose a different endpoint. The great thing is that enabling these endpoints requires minimal changes in your application.


    What do I need to expose these endpoints?

    You will need the following components:-

    1. Visual Studio 2010 or Visual Web Developer Express 2010
    2. Silverlight Tools for Visual Studio 2010 (contains WCF RIA Services for Visual Studio 2010)
      • Contains the OData endpoint
    3. WCF RIA Services Toolkit for SOAP and JSON endpoints

    Creating Endpoints

    Creating an OData Endpoint

    The OData endpoint support is provided out of the box for you. Here is how you can expose an OData Endpoint.

    Creating a new DomainService
    1. Create a new or open up an existing RIA Services Project.
    2. Right click on the server project and add a new DomainService class (assuming you have a DataModel in your project).
    3. When the DomainService Wizard comes up, select the model you want to expose and then check the  “Expose OData Endpoint”
    4. Click Ok
    5. Now you have a DomainService that exposes 2 endpoints:-
      • Binary
      • Odata
    Modifying an existing DomainService to expose an OData Endpoint as well
    1. Create a new or open up an existing RIA Services Project.
    2. Open up your DomainService
    3. Find the query method for your entity type. NOTE: This query method should be parameter less
    4. Add the following attribute on that query method [Query(IsDefault=true)]
         1: [Query(IsDefault=true)]
         2:     public IQueryable<Book> GetBooks()
         3:     {
         4:         return this.ObjectContext.Books.OrderBy(b => b.Title);
         5:     }
    5. Add a reference to System.ServiceModel.DomainServices.Hosting.Odata can be found in Program Files\Microsoft SDK’s\RIA Services
    6. Open up the web.config file and add the following section directly under configuration
         1: <configSections>
         2:     <sectionGroup name="system.serviceModel">
         3:       <section name="domainServices"
         4:                type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection,
         5:                System.ServiceModel.DomainServices.Hosting, 
         6:                Version=, Culture=neutral, 
         7:                PublicKeyToken=31BF3856AD364E35" 
         8:                allowDefinition="MachineToApplication" 
         9:                requirePermission="false" />
        11:     </sectionGroup>
        12:   </configSections>
    7. Under the System.ServiceModel section add the following
         1: <domainServices>
         2:     <endpoints>
         3:       <add name="OData"
         4:            type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />        
         5:     </endpoints>
         6:   </domainServices>
    8. Now compile and run the application

    NOTE: The ODATA endpoint has very limited support in V1. There is no Update or LINQ query support in this release.

    Creating a SOAP and JSON endpoint

    In my earlier post, I had showed how to configure a domain service for a Windows Phone 7 application. In that post I had used the Soap endpoint. Configuring a soap and JSON  endpoint needs the RIA Services toolkit. After you have installed the toolkit, you will need to do the following:-

    1. In the Server project(the one appended with .web) add a reference to Microsoft.ServiceModel.DomainServices.Hosting.dll from %ProgramFiles%\Microsoft SDKs\RIAServices\v1.0\Toolkit\Libraries\Server
    2. Open up the web config file and add the code snippet in Point no 6 for the OData endpoint
    3. Under the System.ServiceModel section add the following.
         1: <domainServices>
         2:     <endpoints>
         4:       <add name="OData"
         5:            type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
         7:       <add name="soap"
         8:             type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        10:       <add name="JSON"
        11:             type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        13:     </endpoints>
        14:   </domainServices>
    4. As you can, we have added the soap and JSON endpoints for the same DomainService. (the two lined just before the endpoints closing tag)
    5. With the additions of these config settings you now have your same Domain Service expose 4 endpoints:-
    • Binary
    • OData
    • SOAP
    • JSON

    Note: You can use SOAP and Json endpoints to submit.

    Consuming these endpoints

    A domain service is a WCF Service; therefore it has a SVC path. You can now access the three endpoint we exposed using that.

    The uri for these endpoints are:-


    OData :http://localhost:[portnumber]/[SLprojectName]-Web-[DomainsServiceName].svc/OData/

    SOAP: http://localhost:[portnumber]/[SLprojectName]-Web-[DomainsServiceName].svc

    JSON: http://localhost:[portnumber]/[SLprojectName]-Web-[DomainsServiceName].svc/JSON/


    With these exposed endpoints, you can talk to multiple clients. In the episode above, I used the following clients:-

    1. Excel Power pivot - Using the OData endpoint
    2. Windows Phone 7 – Using the SOAP endpoint
    3. AJAX client – Using the JSON endpoint

    You can download the source code for the demo from here.



  • @deepeshm

    Installing RIA Services on a server



    As you are all aware that RIA Services currently blocks on a few items during installation. When you download RIA Services today, you need to have the following installed on the machine:-


    1. Visual Studio 2010 with Web Developer or Visual Web Developer express.
    2. .net Framework 4
    3. Silverlight Runtime
    4. Silverlight SDK

    Hosting servers generally do not have Visual Studio 2010 or Silverlight SDK installed, this might be a blocker for some hosting companies.

    The RIAServices msi now has a command line override, especially for hosters. The msi is now configured to take a “Server” command line parameter that will only check for .NET Framework 4.0. The command line parameter will install all the RIA Services server assemblies.

    Here is how to use this option:-

    1. Download the RIA Services MSI and save it on your machine
    2. Open up a command prompt and type the following command.
       1: msiexec /i RIAServices.msi SERVER=true

    Using this option will do the following, install the server assemblies along with adding them to the Global assembly cache and to the native cache (ngen).

    Keep in mind, using this option will not install any of the Silverlight or Tooling components.

    BTW here are some of the hosters that will be supporting RIA Services:-

    DiscountASP - http://labs.discountasp.net/

    OrcsWeb - http://vs2010host.com/

    ASPHostCentral - http://asphostcentral.com/


  • @deepeshm

    RIA Services Release Candidate 2…


    Last Thursday, we released our RC2 build of RIA Services. You can download all the latest bits from http://silverlight.net/riaservices

    These set of bits are compatible with Silverlight 4 RTM and Visual Studio 2010 RTM. I am sure most of you are wondering, why not RTW RIA Services already. Trust me, we would love to release this baby as soon as possible, we are pretty much done. However, we have dependencies on other components. We just need to do the extra bit of testing against these bits to ensure things work fine.

    Last week I got to attend DevConnections and was on Channel 9 talking about RIA Services. You can watch it here Watch Ch9 Live on demand!. My RIA Services segment is at the 2hr and 15 min mark. I talk about our dependencies. Also, be sure to check out the RIA Services book club app in the Silverlight 4 launch keynote. Watch the keynote on demand!

    I know most of you have been asking what new in this version of RIA Services. As the name suggests this is a Release Candidate 2 and there aren’t any new features. However, this release has tons of bug fixes and community reported issues. Here are some of the the changes (some taken from Dinesh’s Post):-

    1. Update of nullable members set to default value are now handled correctly
    2. Drag-drop enhancements: Images are bound one-way by default, ValidateOnException added.
    3. RIA Services framework now has built in ETW traces
    4. Domain Service Wizard now picks up changes in the Data Model.
    5. Toolkit: ASP.net dynamic data template
    6. Toolkit: WCF In-memory tracing support is available, making it easier to troubleshoot failure in shared hosting scenario. (See Tomek’s blog on usage)
    7. Toolkit: WCF client proxy auto generation/updating for WCF Core Service – This enables you to get up-to-date WCF proxy and configuration each time you build your solution, when you add Silverlight-enable WCF service in your Silverlight application.
    8. Other bug fixes

    We would love to hear your feedback so be sure to get back to us via forums, twitter etc.


  • @deepeshm

    RIA Services V1.0 SP1 Beta Released!!


    Moments ago, we released RIA Services V1.0 SP1 Beta along with WCF RIA Services October toolkit. You can download it from http://silverlight.net/riaservices.

    Installation instructions:-

    1. Uninstall WCF RIA Services Toolkit (if installed)
    2. Uninstall WCF RIA Services V1.0 for Visual Studio 2010
    3. Install WCF RIA Services V1.0 SP1 Beta
    4. Install WCF RIA Services Toolkit  October 2010

    These set of bits are compatible with Silverlight 4 and Visual Studio 2010 and are now available for you to download.

    About the download

    This download is contains all the assemblies and is a standalone msi. You do not need to have V1.0 installed in your box and it is completely an in-place update. Just follow the steps above and you should be good to go. Also, this is a Go-Live releaseSmile.

    What’s new in the WCF RIA Services V1.0 SP1 Beta release?

    Shared Entities across multiple DomainServices

    With the latest bits we have dropped the restriction that blocked multiple DomainServices from exposing the same Entity. 

    Support for Complex Objects

    WCF RIA now supports structural non-entity types.

    Client code generation extensibility

    WCF RIA Services now allows the client proxy generator to be replaced, either with a text template or with a plain CLR Type that implements IDomainServiceClientCodeGenerator like this:

       1: namespace MyCodeGenerator
       2: {
       3:     [DomainServiceClientCodeGenerator(typeof(MyCodeGenerator), "C#")]
       4:     public partial class MyT4CodeGenerator : IDomainServiceClientCodeGenerator
       5:     {
       7:         public string GenerateCode(ICodeGenerationHost host, 
       8:                                    IEnumerable<System.ServiceModel.DomainServices.Server.DomainServiceDescription> domainServiceDescriptions,
       9:                                     ClientCodeGenerationOptions options)
      10:         {
      11:             return “Here is generated code”;
      12:         }
      13:     }
      14: }

    A code generator is registered merely by adding to a server project a reference to its assembly, or by declaring the code generator class directly in the server project. MEF is used to recognize the [DomainServiceClientCodeGenerator] attribute among the server’s references. We have also released a TextTemplatingCodeGeneration in the Toolkit that can be used to customize the generated code. Note: the code generator is build on top of this extensibility. 

    Better Binding support for EntitySet and EntityCollection

    EntitySet and EntityCollection now implements ICollectionViewFactory and returns a view when bound to controls likes DataForm and DataGrid. Now you will be able to Add/Remove via a Dataform when it’s bound to a EntitySet and EntityCollection.

    Improved Business Application Template

    · The Login and Registration windows open with focus in the Name field

    · Both windows also listen for the Enter and Escape keys, submitting or canceling accordingly

    · The Windows authentication status control shows an ‘authenticating…’ message

    · And more

    Also check out Kyle’s blog for a customized look of the BAT. This theme is going to be made available only via the Visual Studio Gallery.


    The product, assemblies and templates is now localized into 10 languages. These languages are :-

    • German
    • English
    • Spanish
    • French
    • Italian
    • Japanese
    • Korean
    • Russian
    • Chinese (Simplified)
    • Chinese (Traditional)

    Faster Install

    Hate the time-consuming installer, we heard you. Our installer is now less than a couple of minutes on most machines.

    What’s new in the WCF RIA Services Toolkit October 2010 ?

    With this release of the SP1 beta, we are also releasing a compatible version of the toolkit. The May2010 toolkit will still be available for you to use with V1.0 May release. Note, the October 2010 release will only work with the V1.0 SP1 Beta.

    Here are the new additions:-

    <Shamelessly taken from Tomek’s Blog">

    • Domain Service support for Windows Azure Table Storage. When hosting WCF RIA Services in Windows Azure, you can now easily leverage Windows Azure Table Storage as your data backend. Read more at Kyle McClellan’s blog.
    • T4 template based client code generation. The feature leverages the code generation extensibility point added to the product and provides a well factored and granular mechanism to customize client code generation logic using T4 templates.

    </Shamelessly taken from Tomek’s Blog">


    We would love to hear your feedback so be sure to get back to us via forums, twitter etc.


  • @deepeshm

    Configuring your DomainService for a Windows Phone 7 application



    At Mix 2010, ScottGu talked about the developer story of Windows Phone 7. As you know by now, that the developer story is on Silverlight. I have also seen some questions regarding Windows Phone and whether RIA Services can be used part in it.

    Unfortunately, there is no in built support for the Mobile platform in RIA Services V1.0. I know that is a big bummer because every Silverlight developer is now a windows phone developer. Rest assured we do think RIA Services support for Windows Phone is very important, but it will not make it in our V1.0.

    With that said, you can still enable a Windows Phone 7 application to communicate with a DomainService and here is how…

    At PDC 09, we made a big change, where every DomainService is now a WCF Service. Windows Phone 7 has support for talking to a WCF Service and we can leverage that to our advantage and create a mobile application that talks to a domain service. Yes, you do not get the rich client experience RIA Services provides for Silverlight, but you still get all the benefits of the server richness in the V1 release.

    Here is how you would do that:-

    1. Install the latest Silverlight Tools from here (contains RIAServices, SL4 Sdk, SL4 Runtime etc)
    2. Install the RIA Services March 2009 Toolkit from here
    3. Install the Mobile Tools CTP from here


    Create a new domain service

    I am going to skip over the section on how to create a domain service. You can find that at @brada’s post about exposing data from entity framework. Next we are going to configure the domain service to expose a soap endpoint.


    Configuring a domain service to expose a soap endpoint

    Now that you have have a DomainService configured, we are going to configure it to expose a soap endpoint. In the PDC preview bits this was exposed by default, but we have now scaled that back for various reason. In the RC release you would need to configure your DomainService to be exposed as a WCF Soap Endpoint. Here is how you would do that (assuming you have created a domain service already):-

    1. Install the RIA Services toolkit
    2. In the Server project(the one appended with .web) add a reference to Microsoft.ServiceModel.DomainServices.Hosting.dll from %ProgramFiles%\Microsoft SDKs\RIAServices\v1.0\Toolkit\Libraries\Server image
    3. Once you have added the reference, open up your web.config file and add the following code under the <System.ServiceModel>
         1: <system.serviceModel>
         3:     <domainServices>
         4:       <endpoints>
         5:            <add name="soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
         6:       </endpoints>
         7: </domainServices>
    4. Also add the following in the web.config
         1: <configSections>
         2:     <sectionGroup name="system.serviceModel">
         3:       <section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
         4:     </sectionGroup>
         5: </configSections>
    5. Save the web.config
    6. Compile the application and run it.
    7. Open up a new Internet Explorer window and go to the following address http://localhost:[portnumber]/[SLprojectName]-Web-[DomainsServiceName].svc
    8. You will now see a familiar WCF service screen:-image
    9. You can get to the WSDL by clicking on the wsdl link


    Now that we have configured our DomainService to expose a SOAP endpoint, we can now write a Windows Phone application that talks to it.


    Creating a Windows Phone application that communicates with a DomainService



    1. Launch up Microsoft Visual Studio 2010 Express for Windows Phone. Do not use the Visual Studio 2010 Add on as it does not have Add Service Reference for this Mobile CTP release.
    2. Create a new Windows Phone Applicationimage
    3. Click on the project and select “Add Service Reference'” and type in http://localhost:[portnumber]/[SLprojectName]-Web-[DomainsServiceName].svc  in the Address and Click Go (make sure the service is running from the prior project)image
    4. Click on Ok once the services is found.
    5. Open up MainPage.xaml and add a list box to it.
    6. Open up the Reference.cs from the Service References and look for the entity type that you exposed. In my case i am using Employee from NorthWind
    7. Override the ToString and configure it to display what you like. In my example i did the following
    8.    1: public override string ToString()
         2:   {
         3:       return LastName+", "+FirstName +" Title: " +Title;
         4:   }
    9. Now go to MainPage.xaml.cs and add the following code.
    10.    1: public void LoadEmployee()
         2:      {
         3:          ServiceReference1.DomainService1soapClient client = new ServiceReference1.DomainService1soapClient();
         4:          client.GetEmployeesCompleted += new EventHandler<ServiceReference1.GetEmployeesCompletedEventArgs>(client_GetEmployeesCompleted);
         5:          client.GetEmployeesAsync();
         7:      }
         9: void client_GetEmployeesCompleted(object sender, ServiceReference1.GetEmployeesCompletedEventArgs e)
        10:      {
        11:          this.listBox1.ItemsSource = e.Result.RootResults;
        12:      }
    11. Call the LoadEmployee from anywhere. In my case, i just called it from the Ctor
    12. Run the application
    13. Voila! you now have a windows application talking to a DomainService






    There is a very good sample posted at our code gallery site, that explains how you can do CRUD operation with the SOAP endpoint of a DomainService. You can find it here.



  • @deepeshm

    Theme pack for Silverlight Business Application Released!!


    Last week, we released theme packs for Silverlight Application Templates along with some cool looking themes for the Silverlight Business Application. Download the refreshed Silverlight 4 themes (inlcuding RIA Services templates) here.

    Notes: Courtesy of Tim

    At the link above you’ll find 3 files to download:

    • README_FIRST.txt – please read this :-) but basically I’m writing the same thing here.
    • SL4Themes-templates.zip – this includes a folder for Expression Blend and Visual Studio templates.  The VS folder also has a sub-folder for the RIA Services templates.
    • SL4Themes-rawassets.zip – this is another (optional) zip that includes the resource dictionaries for each template on their own without any Silverlight project.

    The three templates we released are :-


    See it in action here:- http://www.silverlight.net/content/samples/sl4/themes/cosmopolitan.html#/Home


    Windows 7 Theme: 

    See it in action here:- http://www.silverlight.net/content/samples/sl4/themes/windows7.html#/Core


    Accent Color Theme:

    See it in action here:-http://www.silverlight.net/content/samples/sl4/themes/accent.html


    These application make the Silverlight Business Application Template just awesome.

    Cheers and Enjoy!!

  • @deepeshm

    Web 307: Effective RIA Demo Code


    As promised, I am uploading the source code for the demo. Please keep in mind, there are some places where I have not followed best practices, I will follow up with a post after finishing and cleaning up the application. I have had a bunch of folks ask about the source code, so I wanted to get it out there.

    You can download the source here:-




    1. Install RIA Services V1, if you don’t have it. http://www.silverlight.net/getstarted/riaservices/
    2. Download the zip
    3. Unblock it and then Unzip it
    4. Launch the solution and ensure that Web project is set as the startup
    5. Run the application
    6. Register a new user

    Note: If you encounter an error when running the application, just run the application again.


    Check out the admin page where, i create one screen that modifies 8 Lookup Tables. You can do as many as you want.

    Also, check out the Tips page to recap the Tips we covered in the talk.

    I will follow up with a more detailed post with details and steps.


  • @deepeshm

    I want my app to look like the Zune client


    Update: You can download the template from here.

    Earlier I had posted about the theme pack for the Silverlight Business Application and amongst them was the Cosmopolitan template. The cosmopolitan theme is inspired by the Metro theme which was first seen in the the Zune Client.



    Since then, there have been many variations of the Metro theme, Windows Phone 7, Metrotwit, the Cosmopolitan theme  and many more. They are all inspired by the Metro theme. Recently, Nikola. pointed out one of the key differences between the Zune client and the Cosmopolitan theme. One thing, I would like to call out is that they are just different variations. However, I do understand that there is a demand to create a app that looks and feels like the Zune client and in this post I will show you how that can be done using the Cosmo theme.Thanks Tsitsi for your help. She is also the designer that created these designs. I would definitely recommend subscribing to her blog. First download and install the theme pack, the instructions can be found here.

    Making my app look and feel like the Zune client

    Let’s start of by creating a Silverlight Business application Cosmopolitan template. Once that is created, follow these steps:-

    In Fonts.xaml

    1. In the client project, open up Assets\Fonts.xaml
    2. Look for following keys and the change their value
      1. ApplicationNameFontSize to 20
      2. NavigationFontSize to 20
       1: <my:Double x:Key="ApplicationNameFontSize">20</my:Double>
       2: <my:Double x:Key="HeaderFontSize">21.333</my:Double>
       3: <my:Double x:Key="NavigationFontSize">20</my:Double>

    In Styles.xaml

    1. In the client project, open up Assets\Styles.xaml and make the following changes(highlighted in yellow):-
    <!-- ApplicationName Style -->
    <Style x:Key="ApplicationNameStyle" TargetType="TextBlock">
            <Setter Property="Foreground" Value="{StaticResource BlackBrush}"/>
            <Setter Property="FontFamily" Value="{StaticResource ContentFontFamily}"/>
            <Setter Property="FontSize" Value="{StaticResource ApplicationNameFontSize}"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="TextOptions.TextHintingMode" Value="Animated" />
            <Setter Property="Margin" Value="32,-4,0,-3"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
    <!-- Links Border Style -->
    <Style x:Key="LinksBorderStyle" TargetType="Border">
            <Setter Property="Height" Value="40"/>
            <Setter Property="Margin" Value="0,32,10,0"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="VerticalAlignment" Value="Top" />
            <Setter Property="BorderBrush" Value="{StaticResource HighlightBrush}"/>
            <Setter Property="BorderThickness" Value="14,0,0,0"/>
    <!-- Links StackPanel Style -->
    <Style x:Key="LinksStackPanelStyle" TargetType="StackPanel">
            <Setter Property="VerticalAlignment" Value="Bottom"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="Orientation" Value="Horizontal"/>
            <Setter Property="Margin" Value="10,0,0,-7"/>
    <!-- Logo Icon Style -->
        <Style x:Key="LogoIcon" TargetType="ContentControl">
            <Setter Property="Height" Value="30"/>
            <Setter Property="Width" Value="35"/>
            <Setter Property="Margin" Value="0,0,53,0"/>
            <Setter Property="VerticalAlignment" Value="Top" />
            <Setter Property="HorizontalAlignment" Value="Right" />
            <Setter Property="Template">
                    <ControlTemplate TargetType="ContentControl">
                            <Rectangle Fill="{StaticResource HighlightBrush}"/>
    <!-- Content Frame Style -->
        <Style x:Key="ContentFrameStyle" TargetType="navigation:Frame">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Margin" Value="0,75,0,0"/>
            <Setter Property="Padding" Value="30,15,58,15"/>
            <Setter Property="VerticalContentAlignment" Value="Stretch"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <!-- Branding Border Style -->
        <Style x:Key="BrandingBorderStyle" TargetType="Border">
            <Setter Property="Height" Value="Auto"/>
            <Setter Property="Margin" Value="0,0,20,10"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
            <Setter Property="HorizontalAlignment" Value="Stretch"/>

    In ApplicationStrings.resx


    1. Open up Assets\Resources\ApplicationStrings.resx file and make the following changes
      1. AboutPageTitle to “ABOUT”
      2. HomePageTitle to “HOME”
      3. ApplicationName to “application name”

    The end result of these changes will be an application that looks like the Zune Client. Here is a screenshot:-



    Cheers and enjoy!!

  • @deepeshm

    WCF RIA Services Presentation Model Explained


    Earlier this week we released the Beta version of WCF RIA Services for Visual Studio 2008 and the preview version for VS2010 Beta 2. There were a lot of great features added to it from our July CTP.

    Here is a quick list of all the features:-

    1. WCF Integration
    2. Compositional hierarchy
    3. Better error handling
    4. Better support for DomainDataSource
    5. Presentation Model
    6. Inheritance – Visual Studio 2010 Beta 2 only

    You can get details for most of them from http://silverlight.net/riaservices.

    One of the features that I got to work on was the Presentation Model.

    So what is presentation model in WCF RIA Services?

    Exposing DAL types back to client is not a good idea in many ways. The system can go through many changes and can move away from a particular backend to another. This change will require the client to be updated which can be costly. Application developers also have the desire to control what the entity looks like on the client. To address some of these concerns application developers have been adapting the Data Transfer Objects pattern but that does not fit well with RIA services as we have a notion of Domain Object Model where the user can write custom Business Logic. Enters WCF RIA Services presenttion model.

     During the design phase of the feature, we were looking to enable four main scenarios:-

    1. Provide a pattern to create PM types from DAL Types in query methods
    2. Provide a pattern to create DAL Types from PM Type translation in CUD/Custom methods
    3. Provide a way to flow back store generated values back to the client
    4. Provide a way to propagate errors from DAL Types to the client


    In this post I will try to cover up on how you can achieve the top three scenarios, I will follow up with a more detailed post on how to propagate errors back to the client.

    In this blog post I will be using the following DAL Types:-

    1. DAL_Customer
    2. DAL_CustomerPreferences
    3. DAL_CustomerProfile


    I will create the following PresentationModel type and project to the client:-



    In order to create a Presentation Model type you will need to create a new POCO(Plain OLD CLR Object) type in the server project.

    Add this type to your server project.

    public class PM_Customer



        public int CustomerID { get; set; }

        public string Email { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string FavoriteColor { get; set; }

        public string SomeOtherPreference { get; set; }

        public string City { get; set; }

        public string State { get; set; }

        public int Zip { get; set; }



    Projecting Presentation Model type to the client

    Converting DAL type to presentation model types will be a typical scenario for query methods. An application developer can use projection to compose his presentation model type. The code for querying presentation model type would look like:-

    public IQueryable<PM_Customer> GetCustomers()


        return from c in this.Context.DAL_CustomerSet

        select new PM_Customer()


             CustomerID = c.CustomerID,

             Email = c.EmailAddress,

             City = c.CustomerProfile.City,

             FavoriteColor = c.CustomerPreferences.FavoriteColor,

             FirstName = c.FirstName,

             LastName = c.LastName,

             SomeOtherPreference = c.CustomerPreferences.SomeOtherPreference,

             State = c.CustomerProfile.State,

             Zip = c.CustomerProfile.ZipCode




    Updating DAL types from Presentation Model types

    Converting presentation model type to DAL types will be a typical scenario for update or custom methods. An application developer can use projection to compose his presentation model type. The code for updating presentation model type would look like:-



    public void UpdateCustomer(PM_Customer customer)


                        DAL_Customer dalCustomer = this.Context.DAL_CustomerSet.Where(c => c.CustomerID == customer.CustomerID).FirstOrDefault(); 

                        DAL_CustomerPreferences dalPreferences = this.Context.DAL_CustomerPreferencesSet.Where(c => c.CustomerID == customer.CustomerID).FirstOrDefault();

                        DAL_CustomerProfile dalProfile = this.Context.DAL_CustomerProfileSet.Where(c => c.CustomerID == customer.CustomerID).FirstOrDefault();


                       // Custom logic to copy data from PM type to DAL Type  

                       this.MyMerge(customer, dalCustomer);

                       this.MyMerge(customer, dalPreferences);

                       this.MyMerge(customer, dalProfile);              



    In this example MyMerge is a custom function that I wrote which copies values from my presentation model type to my DAL Type. You can choose to do the merge in place.

    Updating Presentation Model types after submit changes.

    Many databases design have fields that are store generated value. E.G. timestamps, ids etc. To flow back these values to the client a developer would need to do the following.




            public void UpdateCustomer(PM_Customer customer)


                DAL_Customer dalCustomer = this.Context.DAL_CustomerSet.Where(c => c.CustomerID == customer.CustomerID).FirstOrDefault();

                DAL_CustomerPreferences dalPreferences = this.Context.DAL_CustomerPreferencesSet.Where(c => c.CustomerID == customer.CustomerID).FirstOrDefault();

                DAL_CustomerProfile dalProfile = this.Context.DAL_CustomerProfileSet.Where(c => c.CustomerID == customer.CustomerID).FirstOrDefault();


                this.MyMerge(customer, dalCustomer);

                this.MyMerge(customer, dalPreferences);

                this.MyMerge(customer, dalProfile);




                this.ChangeSet.Associate(customer, dalCustomer, MapDALCustomerToPMCustomer);        

       this.ChangeSet.Associate(customer, dalPrefernces, MapDALCustomerToPMCustomer); 

       this.ChangeSet.Associate(customer, dalProfile, MapDALCustomerToPMCustomer);               




    The change set will now have a new function called the Associate which will take in instances of PM Type and DAL Types. Once the data is submitted to the database the MapDALCustomerToPMCustomer function will be called with the updated instances.

    private void MapDALCustomerToPMCustomer(PM_Customer pmCustomer, DAL_Customer dalCustomer)


               pmCustomer.CustomerID =  dalCustomer.CustomerId;



    I could set up transform function for each of my DAL Types and flow back the value in to my Presentation Model type and then to the client.


    This post should get you started on presentation model type. I will follow up with a post on how to flow back errors to the client.

  • @deepeshm

    RIA Services RC and Toolkit March 2010 now available…


    The RIA Services team just released the RC version of the product. You can find all the installation instruction @ http://silverlight.net/RIAServices.

    I am going to talk about the features have been added to this release and also introduce you to the RIA Services Toolkit.

    You can download the RIA Services Toolkit here.

    New Features added in the RC Release

    We have added some great features since the PDC 09 release. We have heard all the feedback and tried to address some of the important ones. The list is taken from Dinesh’s forum post. Trust me there have been a lot more additions than the one listed below. I will follow up with more posts or updated links for each feature.


    1. INDEI Support:- Validation support based on Silverlight 4’s INotifyDataErrorInfo. This is a non-exception-based model and enables async validations more easily. It also helps display errors flagged by the server in the UI.

    2. Spiffier DDS: filter/sort/group descriptors support binding; ICommand support for Load/SubmitChanges/RejectChanges

    3. Server throttling: you can regulate the per request load on the server / DB by specifying maximum result limit on a query method using the QueryAttribute.ResultLimit property.

    4. AuthorizationContext: Similar to ValidationContext, now you have more options for implementing custom authorization rules (e.g. entity-based authorization)

    5. Endpoint configuration support: Following the “secure by default” principle, only binary endpoint will be exposed but we have made it really easy to add additional/different endpoints if you plan to use them.

    6. OData endpoint: you can point PowerPivot to a DomainService OData endpoint and analyze data by calling the appropriate query method. This is the first step in lighting up OData with RIA Services.

    Along with these features in the main product, we are also announcing the availability of new package called the RIA Services Toolkit

    What is the Toolkit? What does it contain?

    The WCF RIA Services Toolkit is a collection forward looking features made available outside the normal RIA Services release cycle. A product of the WCF RIA Services product team, the Toolkit adds new functionality quickly for developers and provides the community an efficient way to help shape product development by contributing ideas and bug reports.

    The following functionality are available in this release of the Toolkit:

    1. LinqToSql DomainService
    2. Soap endpoint - This enables you to expose a soap endpoint for your DomainService
    3. JSON endpoint - This enables you to expose a JSON endpoint for your DomainService
    4. ASP.net DomainDataSource - This control will enable you to create an ASP.net application that can talk to your DomainService.
    5. ASP.net  Dynamic Data Domain Service – We have added a new project template for this.


    You can find the breaking changes document here.

    There is quite a bit to play with here and we would love to hear your feedback. You can reach to us at http://forums.silverlight.net/forums/53.aspx


  • @deepeshm

    The inner workings of Count <T> in RIA Services


    One of things that came up repeatedly in our API Reviews for RIA Services was the fact that, we were requesting the total server count of the resulting query by default for paging scenarios.

    This basically meant that were executing two queries on the database:-

    1. Execution on the actual query to get the resulting entities.
    2. Executing another query on to the server to figure out the total number of entities that meet the query.

    This was never an issue for most non-paging scenarios as the framework was optimized for it. Here is the flow in the previous releases:-

    1. If query does not have Take, then the resulting entity count is the same as the total entity count for the query in the database.
    2. If query does have the Take, the framework used to send another query to the server to request the total entity count for the entity in the server.
       1: loadOp = ds.Load<Customer>(ds.GetCustomersQuery());
       2: loadOp.Completed += new EventHandler(loadOp_Completed);

    The count for this query would by 91 entities and the total entity count will also be 91 (No of customers in Northwind database).


    In the latest RIA Services bits, we made a change where the count is not returned by default for paging scenarios.

    Running a query like the one specified above will not have affect on the count and only one query will be executed on the server.

    Now let’s modify the query to look like this and run it on the RC bits:-


    loadOp = ds.Load<Customer>(ds.GetCustomersQuery().Take(10));
    loadOp.Completed += new EventHandler(loadOp_Completed);

    Now let’s look at the count returned from the server:-


    As you can see the TotalEntityCount is –1.

    So now the question arises is that how do i get the count when i add a take. All you need to do is to set the IncludeTotalCount property to true on the EntityQuery. Here is an example to do that:-

    EntityQuery <Customer>loadCustomers = ds.GetCustomersQuery();                   
    loadCustomers.IncludeTotalCount= true;
    loadOp = ds.Load<Customer>(loadCustomers.Take(10));

    Here are the results:-


    DomainDataSource has been optimized to take this change into account and it 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. You can always override this behavior by subscribing to the LoadingData event on the DomainDataSource.


  • @deepeshm

    Using Query.ResultLimit with DomainDataSource


    Server throttling is one the new features we introduced in our RC release.  It lets you regulate the per request load on the server / DB by specifying maximum result limit on a query method using the QueryAttribute.ResultLimit property.

    Here is how you can specify a result limit on a query method:-

       1: [Query(ResultLimit=1000)]
       2: public IQueryable<Customer> GetCustomers()
       3: {
       4:     return this.ObjectContext.Customers;
       5: }

    The result limit query only applies to the top level entities, so the above query will result in returning 1000 top level entities. This limit will not apply to the included entities.

    As you will notice, the ResultLimit will not be propagated to the client. Things get really interesting when you use DomainDataSource especially when you are using LoadSize and PageSize.

    Keep the following in mind, if you are developing an application that happens to have a query limit and uses DomainDataSource on the client:-

    1. Choose the ResultLimit appropriately.
    2. Configure your client to pull data in chunks (DomainDataSource supports this through the LoadSize property).
    3. The load size should be less than or equal to your server query result limit.
    4. Do not have a page size that is greater than the result limit.
    5. It is good practice to have a LoadSize that is a multiple of PageSize.

    Here is an example on how to specify LoadSize and PageSize on DomainDataSource

       1: <riaControls:DomainDataSource 
       2:             AutoLoad="True" 
       3:             LoadSize="20" 
       4:             PageSize="10" 
       5:             Name="customerDataDomainDataSource" 
       6:             QueryName="GetCustomersQuery" 
       7:             Width="0">
       8:     <riaControls:DomainDataSource.DomainContext>
       9:         <my:CustomerContext/>
      10:     </riaControls:DomainDataSource.DomainContext>
      11: </riaControls:DomainDataSource>


  • @deepeshm

    Debugging an OOB Silverlight Business Application


    Recently, we came across a bug with the Silverlight Business Application with respect to an Out of Browser application. In the RTM bits for Silverlight 4 Tools a new feature was added to enable a better debugging experience with Out of Browser application. The feature basically launched the app in OOB window when run with the debugger attached. If you have tried that with the business application template, you will notice that the app does not run. It crashes with an exception, that the URI path is not valid.

    We realize this is an issue most folks are running into and we have fixed this template and we are looking ways to get you access to it. However, there is a relatively easy workaround to fix this issue.

    The steps involved are :-

    1. Create a new or open up an existing application that was created using the BusinessApplicationTemplate
    2. Once the project is open, go to the Project Properties page for the Silverlight Application.
    3. In that, first uncheck the OOB option which is enabled by default


    1. Save the project
    2. Close the Project Property Page
    3. Open the Project Property page again
    4. Then go ahead and check the OOB option.


    1. In doing the stop above, the web server information and all data are now setup correctly.
    2. Run the App
    3. Voila!




  • @deepeshm

    Monitoring a domain service with Windows Server AppFabric dashboard


    At Teched 2010, we announced the RTM of Windows Server AppFabric. I am sure most of you are wondering what Windows Server AppFabric is?

    So, What is Windows Server AppFabric?

    Windows Server AppFabric is a set of integrated technologies that make it easier to build, scale and manage Web and composite applications that run on IIS. You can install and read more about it here. Also, check out the white paper located here. One of the component that Windows Server AppFabric provides is the monitoring AppFabric dashboard in IIS.


    The app fabric dashboards lets you monitor any .NET 4 WCF an WF services with monitoring enabled. As you are all aware that a Domain Service is a WCF service and one of the things we enabled in our RTM build was to enable monitoring for the DomainService. However, this will only work when the web application is hosted in full trust.

    Check out this episode on EndPoint.tv for more deatils

    Endpoint.TV – Windows Server AppFabric in action monitoring and troubleshooting



    How do we enable AppFabric monitoring for a DomainService?

    Enabling AppFabric monitoring for a domain service is very easy. Here is what you would need to do:-

    • Create a new RIA Services project
    • Go to the web project and right click to go to properties
    • Go to the web node and select Use Local IIS Server.


    • Once that is done and your application is configured and running properly, go to the web.config file and add the following entries. One for each DomainService exposed.

       1: <system.serviceModel>
       3:    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
       5:      <serviceActivations>
       6:        <add service="MSTravel.Web.Services.TailSpinTravelService" factory="System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory, System.ServiceModel.DomainServices.Hosting, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" relativeAddress="~/Services/MSTravel-Web-Services-TailSpinTravelService.svc" />
       7:        <add service="MSTravel.Web.AuthenticationService" factory="System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory, System.ServiceModel.DomainServices.Hosting, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" relativeAddress="~/Services/MSTravel-Web-AuthenticationService.svc" />
       8:        <add service="MSTravel.Web.UserRegistrationService" factory="System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory, System.ServiceModel.DomainServices.Hosting, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" relativeAddress="~/Services/MSTravel-Web-UserRegistrationService.svc" />
       9:      </serviceActivations>
      11:    </serviceHostingEnvironment>
      13:  </system.serviceModel>
    • All that we are doing above is to add the activation for SVC less WCF Service.
    • Save the web config and compile and run the application
    • Now go to the IIS and browse to your Virtual Directory and you will notice the AppFabric DashBoard.


    • Double click on the AppFabric Dashboard and you will get all the monitoring information you need.





    You can use the AppFabric dashboard to monitor and track the usage of your DomainService. As you can see it gives you all the error and completed tracked events.

    Cheers and Enjoy!!

  • @deepeshm

    TechEd 2010: The Big Easy


    It’s been a great week at TechEd North America 2010 in New Orleans. There is a very good reason why they call it the Big Easy and now I know:)

    I was really surprised to see the number of folks that came out there and really glad to see the response RIA Services got . I was at the Silverlight booth most of the time and it was just amazing seeing so many questions from so many different people. Its just great to know that so many folks are using our product.

    I had the opportunity to talk at three different occasion during TecheEd, I did a short demo in the JasonZ Developer Foundation Sessions, then i had an interactive session where I talked about accessing web services in Silverlight.

    Here are the recordings for those sessions:-

    Foundations session by Jason Zander. My demo is around the 43 min mark


    Interactive Session ( will update it )

    Breakout Session: WEB 307 – Effective RIA: Tips and tricks for building Rich Internet Application


    I have not had the chance to clean up the source code for all the demos. I will follow up with the code for most of them soon. Stay Tuned!!


  • @deepeshm

    RIA Services Link roundup Part 1


    Earlier in the year, BradA had started this tradition. Each week he would round up links from across the web on RIA Services. I really loved that idea and have decided to continue the tradition.

    Before I get started, here is a little about me:-

    I am a Program Manager on the RIA Services team and have been working on it for the past 18 months now.  These months have been the most enjoyable during my short tenure in Microsoft (~  4.5 years). Prior to joining the RIA Services team, i was working on various other products from Microsoft like Windows Forms, Click Once and BizTalk Server. My team was responsible bringing the Developer Tools for BizTalk Server.

     Anyways let me not bore you with my bio.

    Here are some useful links about RIA Services

    The links above are useful to follow and to get an update about RIA Services.

    Here are some blog entries by some colleagues of mine and by community that illustrate the power of RIA Services:-


    Stay Tuned for more links in the coming days...

     Oh and how about them Colts and Saints....8-0 Baby!!!


  • @deepeshm

    Tech Ed North America 2010 – WCF RIA Services Talk


    Teched 2010 is almost around the corner. It will be held in New Orleans LA from June 7-10. Details and schedule of talks are now published online. I will be attending the conference this year and will actually be giving two talks. The first one as you must have guessed is on RIA Services. Below are the details

    WEB307 | Effective RIA: Tips and Tricks for Building Effective Rich Internet Applications

    Maintainability, testability, performance, and security can be improved by understanding the components and tools and following some basic guidelines. This session uses Windows Communication Foundation RIA Services and Microsoft Silverlight as the key tools and covers the separation of concerns between data access, logic and presentation tiers, best practices for testability and tricks for getting better performance through design. We also cover best practices for locking down your application

    ASI01-INT | Powering Rich Internet Applications: Windows Server AppFabric, Web Services, and Microsoft Silverlight

    Rich Internet Applications (RIAs) rely on platforms such as Silverlight and Windows Phone 7 to present data to users in an interesting and interactive manner. With Windows Communication Foundation (WCF) 4, developers can use a unified programming model for accessing services and data in any Microsoft .NET Framework-based application – including RIAs. This session explores how you can leverage your WCF skills along with rich tooling to build distributed services for the RIA. This talk rationalizes the use case for WCF RIA Services, but focuses mostly on innovations in the core WCF feature set. The talk also shows how WCF simplifies talking to web2.0 services like Bing, REST based service. Also, learn how to build a WCF backend service that enables rich and high performance messaging to RIA Clients like a video chat. By the end of this session you will understand some of the powerful architectures available to you for building RIAs with WCF.

    At Mix 2010, Nikhil tried something different where he had asked the community of the things they would like to see. I really liked that approach and I am looking to follow a similar idea for my talk.

    So, what would you like to see covered? I will definitely try to add it to my demo, if it fits in the overall theme and flow. So please share your thoughts here or email me.

    Looking forward to seeing all of you at Teched in the Big Easy and looking to hear your thoughts on the talk and things you would like to see.


Page 1 of 1 (17 items)