Search code examples
wcfc#-4.0datacontract

Problem with DataContract and hierarchy on WCF


i have a problem with an object in my wcf project. I have lets say this object:

[DataContract(Name="ClassA")]
public class Person{
   //---attributes---
}

[DataContract(Name="ClassB")]
public class Men : Person{
  //---attributes---
}

Where ClassB is child of ClassA on the other side. Then i have a method that is post:

[OperationContract]
[WebInvoke(UriTemplate= "Person", ResponseFormat = WebMessageFormat.Json, Method= "POST")]
public string PostPerson(Person person) {
    if(person is Men){
       //code...
    }
}

The thing is that i receive the person (in the other side, they sendme as a ClassB) but the person is Men returns false.. why?


Solution

  • You need to add the [ServiceKnownType(typeof(Men))] attribute to the PostPerson method.