有什么方法可以隐藏/展平WCF服务数据合同中的基本类型? [英] Is there any way to hide/flatten base types in WCF service data contracts?

查看:76
本文介绍了有什么方法可以隐藏/展平WCF服务数据合同中的基本类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下简单示例:

[DataContract("{0}Base")]
public class Base<T> where T : Entity<T>
{
    // Common methods & properties.  No WCF exposed properties
}

[DataContract]
public class Employee : Base<Employee>
{
    // WCF exposed properties
}

基类Base没有WCF服务使用者感兴趣的属性,但是WCF迫使我也使用[DataContract]属性来注释Base类.这实际上在服务客户端上显示为Employee : EmployeeBase,其中EmployeeBase是一个没有属性的空类.

The base class Base has no properties of interest to the WCF service consumers, but WCF forces me to also annotate the Base class with a [DataContract] attribute. This essentially shows up on the service client as Employee : EmployeeBase with EmployeeBase being an empty class with no properties.

我不想以这种方式向服务公开Base<T>类,那么我有什么选择?

I do not want to expose the Base<T> class to the service in this way, so what are my options?

  1. 用于Employee类的DTO-我宁愿不添加这种复杂性
  2. 平铺" DataContract层次结构,以使Employee的数据协定不会暴露它是从Base<T>继承的.这可能吗?怎么样?
  3. 其他解决方案?
  1. DTO for the Employee class - I'd rather not add this complexity
  2. "Flatten" the DataContract hierarchy so that the data contract for Employee does not expose that it inherits from Base<T>. Is this possible? How?
  3. Other solution?

谢谢.

推荐答案

hiearchy中的每个类都必须可序列化/DataContract.如果您不想公开hiearchy,则必须使用DTO,或者可以尝试为Employee类实现IDataContractSuroggate.

Each class in hiearchy has to be serializable / DataContract. If you don't want to expose hiearchy you have to use DTO or you can try to implement IDataContractSuroggate for your Employee class.

这篇关于有什么方法可以隐藏/展平WCF服务数据合同中的基本类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆