WCF DataContract vs DataContract Interface

后端 未结 2 981
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 13:10

New to WCF.

Can DataContact class inherit from Interface ?

eg:

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


        
2条回答
  •  你的背包
    2021-02-20 13:35

    You can do this:

    [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; }
    }
    

    You can't do this, sadly:

    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; }
    }
    

提交回复
热议问题