c# - WCF DataContract 与 DataContract 接口(interface)

标签 c# wcf

WCF 新手。

DataContact 类可以继承自 Interface 吗?

例如:

[DataContract(Namespace = ...........)]
public class VesselSequence : IVesselSequence
{

    [DataMember]
    public int AllocationId { get; set; }

    [DataMember]
    public string ScenarioName { get; set; }
}

interface VesselSequence : IVesselSequence
{
    public int AllocationId { get; set; }
    public string ScenarioName { get; set; }
}

最佳答案

你可以这样做:

[DataContract(Namespace = ...........)]
public class VesselSequence : IVesselSequence
{
    [DataMember]
    public int AllocationId { get; set; }
    [DataMember]
    public string ScenarioName { get; set; }
}

interface IVesselSequence
{
    int AllocationId { get; set; }
    string ScenarioName { get; set; }
}

遗憾的是,你不能这样做:

public class VesselSequence : IVesselSequence
{
    public int AllocationId { get; set; }
    public string ScenarioName { get; set; }
}

[DataContract(Namespace = ...........)]
interface IVesselSequence
{
    [DataMember]
    int AllocationId { get; set; }
    [DataMember]
    string ScenarioName { get; set; }
}

关于c# - WCF DataContract 与 DataContract 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1090736/

相关文章:

c# - 将存储为文本的数字转换为数字

c# - 发生错误 .", ExceptionMessage: "提供的 'HttpContent' 实例无效

c# - 通过 Internet 向开发人员发送应用程序错误和日志的最佳方式是什么?

c# - asp.net mvc + knockout : Showing validation result from server side logic

wcf - WCF MSMQ 4.0 中的中毒消息处理

wcf - 在IIS中使用wsHttpBinding承载WCF服务的问题

c# - 将 csv 最快导入数据库表

wcf - 什么是选择序列化器

asp.net - 如何在 WCF 服务中记录原始请求

wcf - 将.NET WCF服务发布到Azure