WCF RIA Service – How to configure the WCF Service maximum items returned by the Query

Note: This is post is based on the WCF RIA Services Beta for VS 2008 and the Preview bits for VS 2010 and changes can be done before WCF RIA Services hits RTM.

There are several post on the forums about changing the default number of items passed passed from a DomainService to the client, so I decided to write a short blog post about how to configure the WCF Service of the WCF RIA Services. If you want to know how the WCF RIA Services adds default endpoints etc, you can take a look at my Deep Dive post.

Have the following in mind when creating your DomainService:

There is a wire between the server and the client, so be careful and not pass too much data over the wire. In a enterprise application, an app with a lot of users or low bandwidth it’s advisable to create a light weight class (Data Transfer Object) instead of instead of just passing a DAL type generated from Linq to SQL, Entity Framework or a domain entity. Only pass the data the View needs, this will reduce the number on data passed over the wire. I have helped a lot of customers lately which has major performance issue because they exposes DAL types or domain entities over the wire. There is a reason why for example WCF uses a 65kb message limit by default. It’s to make sure we open up our eyes and notice the network which bounds our client with the server.

If you really need to pass a lot of data over the wire, you may notice that you will get an exception when you have exceeded the default number of item which can be serialized. You can change the maxItemsInObjectGraph size by configuring the WFC RIA Services behavior in web.config, by default this value is 65536 items. By changing the size of how many items which can be serialized and deserialized, you can “register” your service and add a behavior configuration for your service:


  <!— ... -->  

<services> <service name="SilverlightApplication.Web.MyDomainService" behaviorConfiguration="MyDomainService_BehaviorConfig"> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MyDomainService_BehaviorConfig"> <dataContractSerializer maxItemsInObjectGraph="xxxxxx"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>

The Service element name is the “Namespace.DomainServiceName”. You don’t need to change the MaxReceivedMessageSize of the binding, because by default it’s set to: 2 147 483 647 bytes.

1 Comment

Comments have been disabled for this content.