views:

23

answers:

1

I'm using DataContract/DataMembers to serialise my class to JSON for a webservice, and it all works fine, except for one of my members, which could either be class a, or class b, where class b extends class a.

If I omit the KnownType parameter, then an exception is thrown during serialisation:

Type 'ClassB' with data contract name 'ClassB:http://schemas.datacontract.org/2004/07/MyApp.App_Code' is not expected.

As expected, because the ClassB is an extension of Class A, and so not know to the deserialiser. So I need to add a known type attribute, which I do, to the parent Class which contains the member

[KnownType(typeof(ClassB))]
[DataContract]

This compiles fine, but the page which I am currently testing this on seems to go bizzare, it loads fine, however apparently the Service doesn't exist anymore, as my JS call tells me and throws and error. But I have no idea why adding the known type attribute on my class causes the webservice to apparently not exist :s

Is it something to do with the fact that my setup is ClassA, ClassB: ClassA, and all the examples I have seen, seem show a ClassA: ParentClass, ClassB: ParentClass setup.

.NET 4, VWD 2010express

A: 

Yup, it was to do with the class declerations, you can't it the way I was trying to, after creating a base class, and having both of them inherit off them, it worked fine

Psytronic