Sometimes when you are using WCF RIA services with Silverlight using C# or VB to get data from the database to, say, bind to a DataGrid, you might suddenly find yourself staring at this error (this happened to me today):

WCF RIA Error: LoadOperation failed

The reason for this, more often than not, is large number of records being tried to be fetched via a service call and by default WCF RIA services can only handle so many records before they time out after a minute (which is the default timeout setting). The simplest way to get around this is to add the following section (in bold text) in your application’s web.config:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <bindings>
        <basicHttpBinding>
            <binding closeTimeout="01:00:00" openTimeout="01:00:00"
                receiveTimeout="01:00:00" sendTimeout="01:00:00" maxBufferSize="2147483647"
                maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

Basically what this does is increase all the timeouts to 1 hour and increase the maximum number of items the service can return via the maxItemsInObjectGraph attribute. The most important timeouts are openTimeout and recieveTimeout. This link basicHttpBinding will give more information about what each attribute stands for.

This doesn’t discount you from optimising your queries and code but sometimes (such as in my case), you would be just doing a straight forward select from just one table and this error might still happen so there won’t be a lot of room to optimise anything there.

Hope this helps someone somewhere who needs this.

Join the conversation! 1 Comment

  1. Thank you….giving it a try

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Category

Uncategorized

Tags

, ,