I created some data classes inside of my WCF service to transport data back and forth between the service and the client. As such, these “objects” are decorated with [ServiceContract] and [DataMember] thus exposed to the client so that I can instantiate one, fill it in and send it off to the service. Now, I noticed that I can use polymorphism within the service, but I’m not having so much luck doing it between the client and the service. For instance
In the service, there is a class called Ticket and a class called MOCTicket that derives from Ticket. There is also a method that accepts Ticket as an argument. Normally, I should be able to send that method an MOCTicket object and it’ll work fine since it derives from Ticket, and I can do this within the service. However, if I instantiate an MOCTicket object on the CLIENT side and try to send it to the service method that accepts Ticket, it throws errors. I’m guessing this is a serialization issue.
I’m just kind of confused about sort of behaviors I can get out these data classes. You get some but not others. Like I can’t serialize behaviors/methods or constructors, but I can serialize a lazy loaded property (or so it would seem). At any rate, if someone could help me out with achieving what I described above or if it’s possible. Any additional clarification about these “objects” would be appreciated as well. I’ve googled around trying to find answers, but couldn’t find anything written clear enough to answer this. Thanks.
I think I found what I’m looking for, at least at this stage. By adding additional decorations to the service method, I can tell the serializer what types to expect:
And then call like this will work:
I tested to ensure that the service class returning a “base class” type that was actually a derived class in disguised was coming back with all of the additional properties, and it did indeed. Along with a new property called “ExtensionData”. Wunderbar.