Hi,
I have a Windows WCF serivce and Web client. My service has one method
[OperationContract]
SubmitOrder(OrderInfo info)....
// class used to pass all relevant data
[DataContract]
class OrderInfo
{
[DataMember]
OrderType Type;
// general order data
}
It was great until I have introduced new order types (controlled by OrderInfo.Type
property). You can think of new order type as derived from general order (in terms of behaviour).
Each new order has some additional properties. What is the best approach to
implement this polymorphic behaviour of Order?
Currently I simply add new properties to OrderInfo class while adding new orders.
[DataContract]
class OrderInfo
{
[DataMember]
OrderType Type;
// general order data
// First custom order data
// Second custom order data
// TODO - add new properties for new orders
}
I don't like it much cause it too straight. What if I change [DataContract] and the client is not rebuilt?
What are my alternatives? I can of course implement inheritance and derive new [DataContract]
class like MyCustomOrder1
, but inheritance is not supported by serialization, I need to use [KnownTypes]
which is forbidden due to some reasons.