inheritance - WCF: not deserializing knowntype in array as derived class, unsure how to debug datacontractserializer -


i'm new wcf , hoping offer assistance. i've got non-abstract base class has [knowntype] applied derived classes in, , used in body of request service in array. when call service using xml derived class in, in code after deserialization base class, not derived class.

the input xml has xml instance type (xsi:type) attribute appears ignored - whatever set to, system gives me base class no error.

the actual code/etc i'm getting huge. so, i've knocked representative test, works properly, , interestingly, if change xsi:type invalid type, exception datacontractserializer, unlike code want work!

if change name of element force exception, see mention of datacontractserializer:

`start element 'itemz' not match end element 'item'. line 110, position 23. @ system.xml.xmlexceptionhelper.throwxmlexception(xmldictionaryreader reader, string     res, string arg1, string arg2, string arg3)    @ system.xml.xmlutf8textreader.readendelement()    @ system.xml.xmlutf8textreader.read()    @ system.xml.xmlbasereader.skip()    @ system.runtime.serialization.xmlreaderdelegator.skip()    @ readarrayofitemfromxml(xmlreaderdelegator , xmlobjectserializerreadcontext ,     xmldictionarystring , xmldictionarystring , collectiondatacontract )    @    system.runtime.serialization.collectiondatacontract.readxmlvalue(xmlreaderdelegator     xmlreader, xmlobjectserializerreadcontext context)    @     system.runtime.serialization.xmlobjectserializerreadcontext.internaldeserialize(xmlreaderde    legator reader, string name, string ns, type declaredtype, datacontract&     datacontract)    @    system.runtime.serialization.xmlobjectserializerreadcontext.internaldeserialize(xmlreaderde    legator xmlreader, int32 id, runtimetypehandle declaredtypehandle, string name, string     ns)    @ readinteropsectionfromxml(xmlreaderdelegator , xmlobjectserializerreadcontext , xmldictionarystring[] , xmldictionarystring[] ) ... @     system.runtime.serialization.xmlobjectserializerreadcontext.internaldeserialize(xmlreaderdelegator xmlreader, type declaredtype, datacontract datacontract, string name, string ns) @ system.runtime.serialization.datacontractserializer.internalreadobject(xmlreaderdelegator xmlreader, boolean verifyobjectname, datacontractresolver datacontractresolver) @ system.runtime.serialization.xmlobjectserializer.readobjecthandleexceptions(xmlreaderdelegator reader, boolean verifyobjectname, datacontractresolver datacontractresolver)` 

so, i'm bit stumped: judging exceptions, looks it's using datacontractserializer in both cases, in real code, it's not trying use derived type. unlike older asmx style services, have not yet found way of jumping serializer code see on earth doing. doing wrong, , how can debug serializer?

if it's help, can try provide more code/xml. 'demo' code i've got below; real code, uses [messagecontract] service, entities datacontract'd hilt (in real code, svcutil generated proxy code similar attributes).

[datacontract] public class security {     [datamember] public string username { get; set; } }  [datacontract] public class wrapper {     [datamember] public baseentity[] myentities { get; set; } }  [datacontract, knowntype(typeof(advancedentity))] public class baseentity {     [datamember] public string name { get; set; } }  [datacontract] public class advancedentity : baseentity {     [datamember] public int age { get; set; } }  [servicecontract] interface itrivialservice {     [operationcontract] response dostuff(request request); }  [messagecontract] public class request {     [messageheader] public security authenticationdetails { get; set; }      [messagebodymember] public wrapper mywrapper { get; set; } }  [messagecontract] public class response {     [messagebodymember] public baseentity entity { get; set; } }  public class trivialservice : itrivialservice {     public response dostuff(request request)     {         string newname = string.empty;          baseentity entity = request.mywrapper.myentities[0];          //do different depending on entity got         advancedentity advancedentity = entity advancedentity;         if (advancedentity != null)         {             advancedentity.name = request.authenticationdetails.username;             advancedentity.age++;         }         else         {             entity.name = entity.name + " , " + request.authenticationdetails.username;         }          response response = new response();         response.entity = entity;          return response;     } } 


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -