• @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

    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

    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

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


Page 1 of 1 (5 items)