[英]WCF + Silverlight 4: How to configure known types via Web.config?
我想知道當我們使用Silverlight 4客戶端時,是否可以按照本答案中描述的方式配置已知類型?
只有似乎KnownType
東西是使用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文檔 - 基本上,這就是您所需要的:
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.