WCF Service throws error when returning large recordshttp://forums.asp.net/t/1745648.aspx/1?WCF+Service+throws+error+when+returning+large+recordsMon, 12 Dec 2011 19:04:17 -050017456484712017http://forums.asp.net/p/1745648/4712017.aspx/1?WCF+Service+throws+error+when+returning+large+recordsWCF Service throws error when returning large records <p>Hi ,</p> <p>I have used WCF service with my web forms.I have a page that searches records based on the filters.When my records to be fetched exceeds 8000, then it throws error as <strong>&quot;The underlying connection was closed: The connection was closed unexpectedly&quot;.</strong></p> <p>The services returns the data but at the interface level it throws the above error. i have tried using the below code in the Client web.config </p> <p>&lt;endpointBehaviors&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;behavior&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;dataContractSerializer maxItemsInObjectGraph=&quot;2147483647&quot;/&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/behavior&gt;<br> &lt;/endpointBehaviors&gt;</p> <p>and have set the maxReceivedMessageSize,maxBufferPoolSize,maxBufferSize etc as '2147483647' , but still the error persists.</p> <p>Can anyone help me with this problem.</p> <p>Thanks.</p> 2011-12-02T09:58:12-05:004712765http://forums.asp.net/p/1745648/4712765.aspx/1?Re+WCF+Service+throws+error+when+returning+large+recordsRe: WCF Service throws error when returning large records <p>Hi Rashmita,</p> <p>Try using WCF tracing - <a href="http://msdn.microsoft.com/en-us/library/ms733025.aspx"> http://msdn.microsoft.com/en-us/library/ms733025.aspx</a>. That should help you in figuring out exactly which quota was exceeded in your scenario.</p> <p>Thanks.</p> 2011-12-02T18:07:04-05:004717265http://forums.asp.net/p/1745648/4717265.aspx/1?Re+WCF+Service+throws+error+when+returning+large+recordsRe: WCF Service throws error when returning large records <p>Hi,</p> <p>Thank yoy for your reply.</p> <p>I have checked my trace log. It was showing the following error :</p> <p>Exception Type :</p> <p>System.Runtime.Serialization.SerializationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</p> <p>Message :</p> <p>There was an error while trying to serialize parameter http://tempuri.org/:GetUserSearchDetailsResult. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65535'. Change the object graph or increase the MaxItemsInObjectGraph quota. '.&nbsp; Please see InnerException for more details.</p> <p></p> <p>stack trace :</p> <p>System.Runtime.Serialization.XmlObjectSerializerContext.IncrementItemCount(Int32 count)<br> WriteUserSearchDTOToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )<br> System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)<br> System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)<br> System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)<br> System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)<br> System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)<br> WriteArrayOfUserSearchDTOToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , CollectionDataContract )<br> System.Runtime.Serialization.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)<br> System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)<br> System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)<br> System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)<br> System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)<br> WriteUserSearchDTOToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )<br> System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)<br> System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)<br> System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)<br> System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)<br> System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)<br> System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)<br> System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)<br> System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)<br> <br> </p> <p>Where as i have set maxItemsInObjectGraph=&quot;2147483647&quot; in both client's and host's web.config.</p> <p>Any other config settings that i need to change or any other way to solve this problem will be needfull.</p> <p></p> <p>Thanks.</p> <p></p> <p></p> 2011-12-06T07:01:20-05:004719033http://forums.asp.net/p/1745648/4719033.aspx/1?Re+WCF+Service+throws+error+when+returning+large+recordsRe: WCF Service throws error when returning large records <p>Looks like the quota is not getting applied somehow. I believe the exception is seen on the client right?&nbsp;Could you please send me your client configuration at <a href="mailto:piyush.joshi@microsoft.com">piyush.joshi@microsoft.com</a>?</p> 2011-12-07T04:52:08-05:004721643http://forums.asp.net/p/1745648/4721643.aspx/1?Re+WCF+Service+throws+error+when+returning+large+recordsRe: WCF Service throws error when returning large records <p>Hi,</p> <p></p> <p>As per your suggestion i have tried the following code.</p> <p><span style="font-size:9.5pt; font-family:Consolas; color:blue">&lt;</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">client</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">&gt;</span><span style="font-size:9.5pt; font-family:Consolas"></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">endpoint</span><span style="font-size:9.5pt; font-family:Consolas; color:blue"> </span><span style="font-size:9.5pt; font-family:Consolas; color:red">address</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">=</span><span style="font-size:9.5pt; font-family:Consolas">&quot;<span style="color:blue">http://localhost:8732/UserService.svc</span>&quot;<span style="color:blue"> </span><span style="color:red">binding</span><span style="color:blue">=</span>&quot;<span style="color:blue">basicHttpBinding</span>&quot;</span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size:9.5pt; font-family:Consolas; color:red">bindingConfiguration</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">=</span><span style="font-size:9.5pt; font-family:Consolas">&quot;<span style="color:blue">BasicHttpBinding_IUserService</span>&quot;<span style="color:blue"> </span><span style="color:red">contract</span><span style="color:blue">=</span>&quot;<span style="color:blue">UserServiceProxy.IUserService</span>&quot;</span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size:9.5pt; font-family:Consolas; color:red">name</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">=</span><span style="font-size:9.5pt; font-family:Consolas">&quot;<span style="color:blue">BasicHttpBinding_IUserService</span>&quot;<span style="color:blue"> </span><b><span style="">behaviorConfiguration</span><span style="">=</span><span style="">&quot;<span style="color:blue">myBehavior</span>&quot;</span><span style="color:blue">/&gt;</span></b></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp; &lt;/</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">client</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">&gt;</span><span style="font-size:9.5pt; font-family:Consolas"></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp; &lt;</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">behaviors</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">&gt;</span><span style="font-size:9.5pt; font-family:Consolas"></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">serviceBehaviors</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">&gt;</span><span style="font-size:9.5pt; font-family:Consolas"></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">behavior</span><span style="font-size:9.5pt; font-family:Consolas; color:blue"> &gt;</span><span style="font-size:9.5pt; font-family:Consolas"></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">serviceDebug</span><span style="font-size:9.5pt; font-family:Consolas; color:blue"> </span><span style="font-size:9.5pt; font-family:Consolas; color:red">includeExceptionDetailInFaults</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">=</span><span style="font-size:9.5pt; font-family:Consolas">&quot;<span style="color:blue">true</span>&quot;<span style="color:blue"> /&gt;</span></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">serviceMetadata</span><span style="font-size:9.5pt; font-family:Consolas; color:blue"> </span><span style="font-size:9.5pt; font-family:Consolas; color:red">httpGetEnabled</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">=</span><span style="font-size:9.5pt; font-family:Consolas">&quot;<span style="color:blue">true</span>&quot;<span style="color:blue"> /&gt;</span></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">dataContractSerializer</span><span style="font-size:9.5pt; font-family:Consolas; color:blue"> </span><span style="font-size:9.5pt; font-family:Consolas; color:red">maxItemsInObjectGraph</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">=</span><span style="font-size:9.5pt; font-family:Consolas">&quot;<span style="color:blue">2147483647</span>&quot;<span style="color:blue"> /&gt;</span></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">behavior</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">&gt;</span><span style="font-size:9.5pt; font-family:Consolas"></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">serviceBehaviors</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">&gt;</span><span style="font-size:9.5pt; font-family:Consolas"></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">endpointBehaviors</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">&gt;</span><span style="font-size:9.5pt; font-family:Consolas"></span></p> <p class="ecxMsoNormal"><b><span style="font-size:10pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="">&lt;</span></span></b><b><span style="">behavior</span></b><b><span style=""> </span></b><b><span style="">name</span></b><b><span style="">=</span></b><b><span style="">&quot;<span style="color:blue">myBehavior</span>&quot;<span style="color:blue">&gt;</span></span></b><b><span style="font-size:10pt; font-family:Consolas"></span></b></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">dataContractSerializer</span><span style="font-size:9.5pt; font-family:Consolas; color:blue"> </span><span style="font-size:9.5pt; font-family:Consolas; color:red">maxItemsInObjectGraph</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">=</span><span style="font-size:9.5pt; font-family:Consolas">&quot;<span style="color:blue">2147483647</span>&quot;<span style="color:blue"> /&gt;</span></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">behavior</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">&gt;</span><span style="font-size:9.5pt; font-family:Consolas"></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">endpointBehaviors</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">&gt;</span><span style="font-size:9.5pt; font-family:Consolas"></span></p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue">&nbsp;&nbsp;&nbsp; &lt;/</span><span style="font-size:9.5pt; font-family:Consolas; color:#a31515">behaviors</span><span style="font-size:9.5pt; font-family:Consolas; color:blue">&gt;</span></p> <p class="ecxMsoNormal"></p> <p class="ecxMsoNormal"></p> <p class="ecxMsoNormal"></p> <p class="ecxMsoNormal">I added the line<strong> behaviourConfiguration</strong> <span style="font-size:9.5pt; font-family:Consolas"> <span style=""></span></span>on my client's web.config , but it didn't work.</p> <p class="ecxMsoNormal">For trial purpose i have used behavoiurconfiguration in my servuce web.config also but it threw an error</p> <p class="ecxMsoNormal"><br> The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.</p> <p class="ecxMsoNormal"></p> <p class="ecxMsoNormal">Any other method to solve this problem.</p> <p class="ecxMsoNormal">Thanks.</p> <p class="ecxMsoNormal"><span style="font-size:9.5pt; font-family:Consolas; color:blue"></span></p> 2011-12-08T10:17:14-05:004727852http://forums.asp.net/p/1745648/4727852.aspx/1?Re+WCF+Service+throws+error+when+returning+large+recordsRe: WCF Service throws error when returning large records <p>Hi Rashmita,</p> <p>Let me know if you still facing the problem after the changes to the config about specifying named behaviorConfiguration section&nbsp;we discussed over email.</p> <p>Thanks.</p> 2011-12-12T19:04:17-05:00