Friday 14 January 2011

WCF Errors

 

Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.Serialization.SerializationException: Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota.
Source Error:

Line 6:          Dim obj As New PublicSchemeLibrary.SchemeClass()
Line 7: Dim currdate As DateTime = DateTime.Now
Line 8: Response.Write("<HTML><HEAD></HEAD><BODY>" + obj.GetSchemes() + "</BODY></HTML>")
Line 9: Response.Write(ControlChars.NewLine)
Line 10: Response.Write(Environment.NewLine)


Source File: c:\inetpub\wwwroot\UI\Schemes.aspx.vb    Line: 8


Stack Trace:





[SerializationException: Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. ]
System.Runtime.Serialization.XmlObjectSerializerContext.IncrementItemCount(Int32 count) +199
ReadMBPublicSchemeSummaryFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] ) +630
System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context) +83
System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) +39
System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract& dataContract) +1730
System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns) +74
ReadArrayOfMBPublicSchemeSummaryFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString , XmlDictionaryString , CollectionDataContract ) +214
System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context) +220
System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) +39
System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract& dataContract) +1730
System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns) +66
System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName) +1042
System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName) +416
System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName) +66
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest) +152

[NetDispatcherFaultException: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:objSchemes. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. '. Please see InnerException for more details.]
PublicSchemeLibrary.SchemeClass.GetSchemes() in C:\Documents and Settings\lakshmidupati\My Documents\Visual Studio 2005\Projects\UI\PublicSchemeLibrary\SchemeClass.vb:285
Schemes.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\UI\Schemes.aspx.vb:8
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2603


 



Solution :



http://www.devx.com/dotnet/Article/38407/1763/page/2



4. Change the max buffer size and max received message size (if needed).


At run time you may encounter two errors related to the amount of data being served by the server:




  1. The maximum message size quota for incoming messages (65536) has been exceeded.


  2. Maximum number of items that can be serialized or deserialized in an object graph is '65536'.



WCF limits the amount of data you can send over the wire per call to 64K, which is why the first error occurs. If your endpoint has methods that return more data than that (such as a collection), you have to change the buffer size and max received size from 64K to a suitable number.



If you add a service by using the add service reference option, the values added on the server won't always reflect on the client. The client always defaults to 64K, which can cause a lot of confusion if many developers are changing the client configuration. A binding value that is updated on the server will have to be changed again on the client.



To fix the second error mentioned above, you can add the following element to the client config file in the service behavior section (2147483647 is used as an example only):



 


<dataContractSerializer maxItemsInObjectGraph="2147483647" /> 


 



 



Fisrt we must add a section to our app.config servicemodel  : endpoint behavior:




    <behaviors>

      <endpointBehaviors>


        <behavior name="Graph">


          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>


        </behavior>


      </endpointBehaviors>


    </behaviors>




Then at your endpoint you can reference it:



<client>



<endpoint address=http://DomainName/PublicScheme/default.svc


          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPublicScheme"


          contract="WCF_PublicScheme.IPublicScheme" name="BasicHttpBinding_IPublicScheme" behaviorConfiguration="Graph"/>


    </client>



It should solve the problem.

1 comment:

  1. Thank you so much,
    I did as other weblog and msdn post said but it did not work, the point was the "behaviorConfiguration="Graph"
    which you cited in red font.

    :)

    ReplyDelete