WCF + Silverlight 4: How to configure known types via Web.config?
I want to know if it is possible to configure known types the way described in this answer when we are using a Silverlight 4 client?
Only thing that seems to work is using the KnownType
attribute, and we'd like to avoid that solution since the classes are in different assemblies and we don't want dependencies between them.
Here's a sample of the configuration:
<?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>
Check out the MSDN docs on the topic - basically, this is what you need:
<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>
精彩评论