我想知道是否可以按照 this answer 中描述的方式配置已知类型当我们使用 Silverlight 4 客户端时?
唯一似乎有效的方法是使用 KnownType
属性,我们希望避免该解决方案,因为这些类位于不同的程序集中,我们不希望它们之间存在依赖关系。
这是配置示例:
<?xml version="1.0"?>
<configuration>
<!-- *snip* -->
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="Foo.Dto.FooDto, Foo.Dto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL">
<knownType type="Foo.Dto.BarDto, Foo.Dto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL" />
<knownType type="Foo.Dto.BizDto, Foo.Dto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL" />
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
<!-- *snip* -->
</configuration>
最佳答案
查看 MSDN docs关于主题 - 基本上,这就是您需要的:
<configuration>
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="MyCompany.Library.Shape, MyAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=XXXXXX, processorArchitecture=MSIL">
<knownType type="MyCompany.Library.Circle, MyAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=XXXXXX, processorArchitecture=MSIL"/>
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
</configuration>
关于c# - WCF + Silverlight 4 : How to configure known types via Web. 配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5190332/