Sreedhar
Sreedhar

Reputation: 30045

WCF DataContract vs DataContract Interface

New to WCF.

Can DataContact class inherit from Interface ?

eg:

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

Upvotes: 10

Views: 9530

Answers (2)

JohnLBevan
JohnLBevan

Reputation: 24470

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

Upvotes: 5

Martin Moser
Martin Moser

Reputation: 6267

sure it can, but keep in mind if you are returning the interface type you have to define the KnownTypes attribute for deserialization engine, so it could deserialize your sent interface at the other end.

Upvotes: 3

Related Questions