Toady we ran into an issue where the serialization graph of our objects exceeded the default max limits (yea I know, I need to resolve this as my root issue, but one step at a time). When I used the WcfTestClient to test for a working solution for my problem I simply had to make a few config changes. In fact I only needed to add the following to my config
<behaviors>
<endpointBehaviors>
<behavior name="Behaviors.EndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
AND
<client>
<endpoint address=http://localhost:9997/Services/MyService
behaviorConfiguration="Behaviors.EndpointBehavior"
binding="wsHttpBinding" bindingConfiguration="WSHTTPBinding.Configuration.Client"
contract="IAppointments" name="Client.EndpointConfiguration" />
</client>
However, because we are not using straight config to drive our WCF this solution was not something we could use. Long story short we basically spin up our endpoints on our client dynamically. Because of this we need to set the MaxItemsInObjectGraph property by hand. I had expected i could create an instance of my endpoint Behavior I had created above (Client.EndpointConfiguration) and push this behavior to my at the service level and be done with it. But from all my googling all I could find online has you setting this property on each operation on the contract.
foreach ( var operation in channelFactory.Endpoint.Contract.Operations )
{
var behavior = operation.Behaviors.Find() as DataContractSerializerOperationBehavior;
if ( behavior != null )
{
behavior.MaxItemsInObjectGraph = 2147483647;
}
}
Now, I am reaching out to the blogosphere to ask, is there a better way to do this?
Till next time,
Posted
05-04-2010 1:06 PM
by
Derik Whittaker