Answered by:
Declaration of dataContractSerializer maxItemsInObjectGraph is not being used when declared in App.config

Question
-
Hi
I have a WCF service with 2 methods, both using a class declared as DataContract...
One of the methods in the class has a list of references to other objects...So I was getting an error message about maxItemsInObjectGraph and that I needed to increase it...
I declared this parameter on both service sice (in Web.config in service and endpoint behaviour) and on client side (in App.config in endpoint behaviour)...
But, for some reason the client is not using this configuration at all...I wrote a small console app as a client that uses service reference for testing purposes...
The program has following block of code:var client = new MyServiceClient(); foreach (var operation in client.Endpoint.Contract.Operations) { Console.WriteLine("\n List of behaviors for operation: [{0}] :", operation.Name); foreach (var behaviour in operation.Behaviors) { Console.WriteLine("\t"+behaviour.ToString()); if (behaviour.GetType() == typeof(DataContractSerializerOperationBehavior)) { var dataContractSerializerBehavior = (DataContractSerializerOperationBehavior)behaviour; Console.WriteLine("\t\tMaxItemsInObjectGraph: {0}", dataContractSerializerBehavior.MaxItemsInObjectGraph); } } }
The output is:
List of behaviors for operation: [Initialize] : System.ServiceModel.Dispatcher.OperationInvokerBehavior System.ServiceModel.OperationBehaviorAttribute System.ServiceModel.Description.DataContractSerializerOperationBehavior MaxItemsInObjectGraph: 65536 System.ServiceModel.Description.DataContractSerializerOperationGenerator List of behaviors for operation: [Archive] : System.ServiceModel.Dispatcher.OperationInvokerBehavior System.ServiceModel.OperationBehaviorAttribute System.ServiceModel.Description.DataContractSerializerOperationBehavior MaxItemsInObjectGraph: 65536 System.ServiceModel.Description.DataContractSerializerOperationGenerator
So obviously, the client is not using the configuration as declared in App.config...
Here is App.config (for client):<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="MyService_wsHttp_Behavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> </endpointBehaviors> </behaviors> <bindings> <wsHttpBinding> <binding name="MyService_wsHttp" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> <security mode="Message"> <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" /> <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" /> </security> </binding> </wsHttpBinding> </bindings> <client> <endpoint address="http://localhost/Services/MyService.svc" behaviorConfiguration="MyService_wsHttp_Behavior" binding="wsHttpBinding" bindingConfiguration="MyService_wsHttp" contract="MyServiceReference.MyService" name="MyService_wsHttp"> <identity> <servicePrincipalName value="host/pcname" /> </identity> </endpoint> </client> </system.serviceModel> </configuration>
Here is also Web.config of the service (although I think its the client that is not using the setting):
<?xml version="1.0"?> <configuration> <connectionStrings> <add name="MyEntities" connectionString="...omitted..." providerName="System.Data.EntityClient" /> </connectionStrings> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <services> <service behaviorConfiguration="MyService_Behavior" name="Services.MyService"> <endpoint address="" behaviorConfiguration="MyService_wsHttp_Behavior" binding="wsHttpBinding" bindingConfiguration="" name="MyService_wsHttp" bindingNamespace="http://schemas.my.com/2010/10/MyService" contract="Services.Contracts.IMyService" /> <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" name="MyService_mexHttp" bindingNamespace="http://schemas.my.com/2010/10/MyService" contract="IMetadataExchange" /> </service> </services> <behaviors> <endpointBehaviors> <behavior name="MyService_wsHttp_Behavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="MyService_Behavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>
Can anyone tell me why is my client not using the configuration?
I am suspecting the issue is in client side as the setting is not being "set" even before I call the service method with the client proxy...Any help would be appreciated...
Zam6ak...
Thursday, October 14, 2010 6:59 PM
Answers
-
Hi,
Your configuration is correct, and the proxy is actually using the new maxItemsInObjectGraph value (2147483647) too. Only the way you print out maxItemsInObjectGraph is wrong.
The dataContractSerializer behavior is set in endpoint level at your case. So the value is kept in endpoint level. In client.Endpoint.Behaviors, there is a
System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior (which is an inner class), this behavior has the value you set in the configuration.
- Proposed as answer by Juyu ZhengMicrosoft employee Friday, October 15, 2010 8:59 AM
- Marked as answer by zam6ak Monday, October 18, 2010 9:05 PM
Friday, October 15, 2010 8:58 AM