【发布时间】:2010-02-08 17:22:59
【问题描述】:
我正在尝试将“集合集合”转换为更好看的 xml。基本上,我想对服务消费者撒谎,让它看起来像有一个真实的对象。
这是 WCF 自动创建的内容
<EntityPropertyCollection xmlns="http://schemas.datacontract.org/2004/07/CustomSerializer" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<EntityProperty>
<Name>Test</Name>
<Value i:nil="true"/>
</EntityProperty>
<EntityProperty>
<Name>Test2</Name>
<Value i:type="EntityPropertyCollection">
<EntityProperty>
<Name>Nested1</Name>
<Value i:nil="true"/>
</EntityProperty>
<EntityProperty>
<Name>Nested2</Name>
<Value i:nil="true"/>
</EntityProperty>
</Value>
</EntityProperty>
</EntityPropertyCollection>
这就是我想要实现的目标
<Something>
<Test i:nil="true"/>
<Test2 i:type="Something">
<Nested1 i:nil="true"/>
<Nested2 i:nil="true"/>
</Test2>
</Something>
特定类型 (EntityProperyCollection) 的自定义序列化器会很好,但其他帖子表明这不是一个选项。
我查看了数据合同代理。我想我可以生成一个自定义类型并允许 DataContractSerializer 序列化生成的类型。但是,我希望有一个更简单的解决方案。
【问题讨论】:
标签: wcf serialization