Send Large Data Sets from WCF to Silverlight

Send Large Data Sets from WCF to Silverlight

The web.config alteration allows a WCF service to feed large blocks of data to Silverlight. If your initial testing of a Silverlight application worked but now you are failing on large production data, this tip may be for you. Full credit goes to Syed Mehroz Alam, who diagnosed the problem and documented the solution in his blog post, “Retrieving huge amount of data from WCF service in Silverlight application.” I’m reproducing his solution here to give it a wider audience. I sweated blood over this until I stumbled across Syed’s blog.

Today, I was trying to figure out why my WCF service call always threw the generic NotFound exception when trying to retrieve large datasets. I had all the buffer limits set to 2147483647 (int.MaxValue) in the Silverlight service configuration file and in the WCF service configuration section under web.config.

Some analysis revealed that I was getting a System.Net.WebException:

The underlying connection was closed: The connection was closed unexpectedly.

After some research, I found that I need to set the maxItemsInObjectGraph for dataContractSerializer to some higher value in my web.config.

If you are trapped in a similar situation, here are two steps to ensure that you can retrieve large amounts of data from a WCF service:

  1. Enable the Silverlight client to retrieve huge chunks of data by enabling large buffers. You need to increase buffer and message size limits for the binding inside ServiceReferences.ClientConfig with something like this:
    01<system.serviceModel>02    03        04            07                08            09        10    11    12        15    16
  2. Enable the WCF service to send large amounts of data. You need to set the binding buffer limits as well as the DataContractSerializer’s maxItemsInObjectGraph value. Here’s an extract from web.config with all the limits set to maximum:
    0102    03        04            05            09                15            16        17    18 19    20        21            22            23                24                25                26            27        28    29 30    31    32        33        35            38            39        40    41

That’s all it takes to send greater amounts of data from a WCF service to a Silverlight application. However, if you want to send large amounts of data from Silverlight to a WCF service, you need one more step because you can reach the maximum permitted HTTP request length (4MB by default). This again can be solved by tweaking the web.config. For example, you need something like this to allow 10MB of data:

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several