Link to home
Start Free TrialLog in
Avatar of modotx
modotxFlag for United States of America

asked on

WCF Service won't pass back inherited class

Ok as we all know in OO programming one should program to the interface or to the abstract/base class.  I have created a service which has two methods one returning an instance of the base class and another returning an instance of a concrete class that inherits from the base class.  

To call these service methods, I created a client application.  The service method returning an instance of the base class works but the method returning an instance of the class which inherits from the base class doesn't (some sort of communication error or so it claims).  I tried using the KnownType Attribute to no avail.  What am I missing?  I have attached a zip file with the projects.  You will need to add a reference to the service since some filetypes are not allowed to be uploaded.

TIA,
Mo MyTest.zip
ASKER CERTIFIED SOLUTION
Avatar of theHollow
theHollow
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of modotx

ASKER

It more than helped, it worked!  :)

All of the examples I was looking at did not explain clearly where the KnownType attribute should be placed with the base class and that it only applied to return types of methods.  As a matter of fact, some said it wasn't necessary to to use the KnownType.

I wonder why the serializer can't or isn't built with enough smarts to deduce the inheritance tree.  Is it just about performance?

Thank you so much though.
Avatar of modotx

ASKER

Thanks again!
Hehe
No problem :-) I have been fighting the same problem before.

So KnownType is highly necessary. It only works a little different way than one might think is logical at first.
I don't know why it's like that, but I bet it's about performance and to reduce the number of bytes to send over the internet.

Wishing a good week-end :-)