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

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.
Thank you….giving it a try