c# - WCF + Silverlight 4 : How to configure known types via Web. 配置?

标签 c# wcf silverlight-4.0

我想知道是否可以按照 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/

相关文章:

c# - 将泛型传递到类构造函数列表中

c# - 无效操作异常

c# - 调用 WCF 引用类型变量

silverlight-4.0 - Silverlight TreeViewItem,绑定(bind)到 IsSelected,如何?

silverlight - 是否有可能得到 x :Name of a DependencyObject (Silverlight)?

c# - Windows Phone 7 配置/应用程序设置?

c# - Visual Studio 2010 中的自定义调试输出

C# 等效于 C++ ostream::tellp 用于磁盘上的大小限制

c# - 跨域 Cookies 问题 (ASP.NET)

jquery - 错误: Cannot process the message because the content type 'application/json; charset=utf-8 was not the expected type