We are currently developing an LOB application and one of the screens in Silverlight shows about 20,000 records. When the (Silverlight) client made the domain service call it got back no data. This was because the database calls took a long time and returned many records. This led to problems with RIA services on 2 levels viz. timeouts (the time the call takes to return) and the number of objects returned.
To resolve this, I did the following:

Setting the timeout

To work around the default timeout of 30 secs for RIA services, we need to over-ride the the timeout of the binding for the endpoint at run-time.
This is a simple concept but tricky to implement. The idea is to create a partial class that will complement the DomainContext class auto-generated for the Silverlight client.

To get a handle on this, open the auto-generated file by RIA services during compilation, named [your project].g.cs in a hidden Generate Code folder. To view this, click the Project for your Silverlight client as specified in the RIA services link.

image

Click on the “Show All files” button icon in VS2010 and you will see it.

This file will contain the proxy Domain Context class generated for calling your Domain Service, amongst many other namespaces and classes in that file. Ensure you have the right namespace for this class (it could be confusing) which is essentially the namespace of your Domain Service.

Create a partial class for this Context.
Make a new file and add code similar to the following to it
(replace myns and MyDomainContext with yours, and the required timeout value which I have as 5 minutes)

namespace myns
{
    public sealed partial class MyDomainContext
    {
        partial void OnCreated()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                ((WebDomainClient<MyDomainContext.IMyDomainServiceContract>)this.DomainClient)
                    .ChannelFactory.Endpoint.Binding.SendTimeout = new TimeSpan(0, 5, 0);
            }
        }
    }
}

 

Add a reference to the web client of Domain Services

image

If the class you added does not compile, check the namespace and the Interface name (from the hidden file for that domain context constructor) and the reference.

Changing the number of objects returned

RIA Services limits the number of objects that can be returned, and this limit can be over-ridden by modifying the service behavior (not the client). This is done by modifying the web.config file to first specify a behavior node

The existence of the behavior node is specified in the services section

<services>
  <service name="myNS.myDomainService" behaviorConfiguration="myDomainService" />
</services>
The actual behavior node is specified in the behaviors node in the system.serviceModel section. Minimize the number of objects returned to suit your needs
<behaviors>
<serviceBehaviors>    
<behavior name="myDomainService">
  <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="true" />
     <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
The above changes should hopefully work for you as well.
Advertisements