有没有办法隐藏/展平 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] 属性注释基类。这本质上在服务客户端上显示为 Employee : EmployeeBase
,其中 EmployeeBase
是一个没有属性的空类。
我不想以这种方式向服务公开 Base
类,那么我有什么选择?
- Employee 类的 DTO - 我不想添加这种复杂性
- “扁平化”DataContract 层次结构,以便 Employee 的数据协定不会暴露它继承自
Base
。这可能吗?如何? - 其他解决方案?
谢谢。
Consider the following simple example:
[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
}
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.
I do not want to expose the Base<T>
class to the service in this way, so what are my options?
- DTO for the Employee class - I'd rather not add this complexity
- "Flatten" the DataContract hierarchy so that the data contract for Employee does not expose that it inherits from
Base<T>
. Is this possible? How? - Other solution?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
层次结构中的每个类都必须可序列化/DataContract。如果您不想公开层次结构,则必须使用 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.