Wcf 嵌套列表序列化

Wcf 嵌套列表序列化,wcf,serialization,silverlight-3.0,Wcf,Serialization,Silverlight 3.0,我无法将我的对象从WCF传输到SL3 interface IComposite { ICollection<Child_A> Children{ get; set; } } [DataContract] [knownType(typeof(ChildCollection))] [knownType(typeof(ICollection<Child_A>))] class Composite : IComposite { ChildCollection c =

我无法将我的对象从WCF传输到SL3

interface IComposite {
   ICollection<Child_A> Children{ get; set; }
}
[DataContract]
[knownType(typeof(ChildCollection))]
[knownType(typeof(ICollection<Child_A>))]
class Composite : IComposite {
    ChildCollection c = null;
    [DataMember]
    public string Name { get;set;}
    [DataMember]
    public ICollection<Child_A> Children { get { 
         return c??(c=new ChildCollection()); 
    }  set;}
}
[CollectionDataContract]
class ChildCollection : List<Child_A> {
}
[DataContract]
class Child_A {
    [DataMember]
    string Name { get;set; }
}
[OperationContract]
Composite GetData(){
   var data = new Composite();
   data.Children.Add( new Child_A() { Name = "child_a_1" } );
   return data;
}
当我从SL3调用服务时,我得到了复合对象,但列表中没有项目。组合中还有其他集合。当我设置[DataMemberOrder=0/1]时,我在客户端上得到错误nullreference error。如果我删除它,我会得到一个找不到的错误。我尝试了KnowType和ServiceKnownType,但没有成功。我检查了svcTrace,它只是说序列化错误。我做错了什么

SVC跟踪 InnerException消息为“Type”xxxCoverageEntity“,数据协定名称为“xxxCoverageEntity:”不应出现。将任何静态未知的类型添加到已知类型列表中


这里xxxcoveragentity是示例中的子对象

您需要使用DataMember对集合进行注释,否则它将根本无法序列化。您还需要使用KnownTypeOfChildCollection注释DataContract,否则它不知道ICollection是什么类型的东西,因此也不知道如何序列化它


类似地,您需要向Child_添加[DataMember]Name属性,否则它将无法序列化

我以前和现在都尝试过这一点,但在客户端我得到了NullReference异常。更新后的帖子是我现在拥有的,当我从Children属性中删除[DataMember]时,它将以空列表序列化,否则为nullreference Exception您可以通过创建控制台应用程序并调用服务来检查这是否纯粹是Silverlight内容吗?GetData中的代码是否应该读取data.Children.Add?根据您所展示的内容,您在复合上没有添加操作。您还可以在服务中打开消息日志记录,并确保数据从服务中删除吗?对,它的children.add。添加了svcLogHey的跟踪,也许你有解决这个问题的方法?