[DataContract]
public class UserCertification
{
…
}
[DataContract]
public class UserPhone
{
…
}
[DataContract]
public class UserAddress
{
…
}
[DataContract]
public abstract class Request
{
[DataMember]
public int UserMakingRequest { get; set; }
[DataMember]
public Guid RequestId { get; set; }
[DataMember]
public Object RequestObjectDTO { get; set; }
}
var request = new Request
{
RequestId = new Guid(),
UserMakingRequest = loggedInUserId,
RequestObjectDTO = userCertification,
};
I have DataContracts: UserCertification, UserAddress and UserPhone
I also have a DataContact Request. This is what I would like to pass to each WCF service method.
So notice in the Request DataContract is DataMember called RequestObjectDTO. I made this of type object, hoping I would then be able to attach my other DataContracts to it.
This did not work – it throws the error “Cannot create an abstract class.”
What type should it be of? Can I do this?
That is the point of abstract class – you can’t create its instance. You must create instace of derived non abstract class but in such case you must mark your
Requestclass withKnownTypeAttributedescribing child classes which can be transported by WCF messages. Moreover WCF doesn’t like object type asDataMember– it will not work because WCF must know what type should be deserialized on a client.