我只能序列化167条记录。任何其他抛出mscorlib.dll中发生未处理的“System.StackOverflowException”类型异常

时间:2013-10-02 01:38:23

标签: c# .net wcf silverlight serialization

说实话,我完全筋疲力尽,我真的不知道该怎么做。我正在使用Silverlight wcf开发Silverlight应用程序。我的webconfig看起来像这样:

<system.web>
<httpRuntime maxRequestLength="2147483647" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information,Error,ActivityTracing"     propagateActivity="true" >
<listeners>
<add name="xml" />
</listeners>
        </source>
        <source name="CardSpace">
            <listeners>
                <add name="xml" />
            </listeners>
        </source>
        <source name="System.IO.Log">
            <listeners>
                <add name="xml" />
            </listeners>
        </source>
        <source name="System.Runtime.Serialization" switchValue="Information,Error,ActivityTracing">
            <listeners >
                <add name="xml" />
            </listeners>
        </source>
        <source name="System.IdentityModel">
            <listeners>
                <add name="xml" />
            </listeners>
        </source>

        <source name="System.ServiceModel.MessageLogging">
            <listeners>
                <add name="xml"/>
            </listeners>
        </source>
        <source name="myUserTraceSource"
                switchValue="Information, ActivityTracing">
            <listeners>
                <add name="xml"/>
            </listeners>
        </source>
    </sources>
    <sharedListeners>
        <add name="xml"
             type="System.Diagnostics.XmlWriterTraceListener"
                   initializeData="e:\Traces.svclog"

             />
    </sharedListeners>
</system.diagnostics>


<system.serviceModel>

    <diagnostics>
        <messageLogging
 logEntireMessage="true"
 logMalformedMessages="true"
 logMessagesAtServiceLevel="true"
 logMessagesAtTransportLevel="true"
 maxMessagesToLog="3000"
  maxSizeOfMessageToLog="2147483647"
 />

    </diagnostics>

    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
                <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
                <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>

    <bindings>
        <basicHttpBinding>
            <binding name="ServicesBinding" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
             maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                 maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
        </basicHttpBinding>
    </bindings>


    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
        <service behaviorConfiguration="ServiceBehavior" name="SUS.Web.Services.BaseService">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ServicesBinding"
             contract="SUS.Web.Services.BaseService" />
        </service>
        <service behaviorConfiguration="ServiceBehavior" name="SUS.Web.Services.NuggetServices">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ServicesBinding"
             contract="SUS.Web.Services.NuggetServices" />
        </service>
        <service behaviorConfiguration="ServiceBehavior" name="SUS.Web.Services.WorkspaceServices">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ServicesBinding"
             contract="SUS.Web.Services.WorkspaceServices" />
        </service>
        <service behaviorConfiguration="ServiceBehavior" name="SUS.Web.Services.GeneralTemplateService">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ServicesBinding"
             contract="SUS.Web.Services.GeneralTemplateService" />
        </service>
        <service behaviorConfiguration="ServiceBehavior" name="SUS.Web.Services.QueryService">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ServicesBinding"
             contract="SUS.Web.Services.QueryService" />

        </service>
    </services>
</system.serviceModel>        

我在服务器和Silverlight项目之间共享程序集,所以我可以在它们之间发送类。服务器生成250个对象。我可以发送它们最多167个。我可以从这250个中选择任何167个VmNugget对象,这不是任何具体对象的问题。我的ViewModel非常复杂,可以互相包含,也可以是另一个的祖先。 MY类使用[DataContract]和[DataMember]属性进行修饰。您有什么提示我如何在序列化过程中检查过程?我的webService以这种方式装饰:

[ServiceKnownType(typeof(VmCulture))]
[ServiceKnownType(typeof(VmNugget))]
[ServiceKnownType(typeof(VmDesignedNugget))]
[ServiceKnownType(typeof(VmDesigner))]
[ServiceKnownType(typeof(OperationLog))]
[ServiceKnownType(typeof(OperationLog))]
[ServiceKnownType(typeof(VmFile))]
[ServiceKnownType(typeof(VmQuery))]
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class QueryService : BaseService

有趣的事情:

我已从这样的属性中删除了所有构造函数:

private ObservableCollection<VmNugget> my;
[DataMember]
public ObservableCollection<VmNugget> My
get{
/* commented
if (this.my == null)
 this.my = new ObservableCollection<VmNugget>();
*/ 
return this.my;
}

我试图将超过167个空对象放到返回的集合中,我无法将它们序列化并发送给客户端。这些对象应为空(未初始化)。

我使用VmQuery类和Rows属性中的OBservableCollection发送它。

非常感谢你。

托马斯

3 个答案:

答案 0 :(得分:2)

My ViewModels are pretty complex, can contain each other and one can be ancestor of another one.

这可能是您的问题所在。我怀疑你有几个对象,它们之间有一个循环引用,并且序列化器溢出。检查这种方法的一种方法是尝试一次一个地序列化每个对象(以及它的子对象)。我敢打赌,其中一个(或可能更多)会表现出你所描述的行为。

考虑按ID而不是完整对象本身序列化对子对象的引用。

答案 1 :(得分:0)

确保没有无限循环或无限递归。 太多的方法调用通常表示非常深或无限的递归。

MSDN

答案 2 :(得分:0)

非常感谢你。我终于找到了它。在一个属性中,我使用了OBservableCollection后代。这个类正在添加一个精彩的能力来记住对每个包含对象的父集合的引用。 :-)解决了,我还活着。世界如此美丽。