简体   繁体   English

WCF + Silverlight 4:如何通过Web.config配置已知类型?

[英]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? 我想知道当我们使用Silverlight 4客户端时,是否可以按照本答案中描述的方式配置已知类型?

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. 只有似乎KnownType东西是使用KnownType属性,我们希望避免使用该解决方案,因为这些类位于不同的程序集中,我们不希望它们之间存在依赖关系。

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: 查看关于该主题的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM