XmlSerializer Deserialize failures

Posted by smvlad on Stack Overflow See other posts from Stack Overflow or by smvlad
Published on 2010-04-06T22:56:21Z Indexed on 2010/04/07 0:43 UTC
Read the original article Hit count: 985

Filed under:
|
|

I have wsdl from third party server. Method that i'm interested in returns XmlNode. My thought was wrap web methods and use XmlSerializer to return strongly typed objects. Returned xml looks like this (i removed soap headers):

<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:type="ResponseExt" 
        xmlns="http://www.thirdparty.com/lr/">
  <Code>0</Code>
  <Message>SUCCESS</Message>
  <SessionId>session_token</SessionId>
</Response>

Looked simple. Created a class:

[XmlRoot("Response")]
public class MyClass {
    public string Code {get; set;}
    public string Message {get; set;}
    public string SessionId {get; set;}
}

Processing time:

//XmlNode node = xml from above
XmlSerializer serializer = new XmlSerializer(typeof(MyClass));
XmlNodeReader reader =  new XmlNodeReader(node);
Myclass myclass = serializer.Deserialize(reader) as MyClass

Last line is where it blows up with inner exception message: The specified type was not recognized: name='ResponseExt', namespace='http://www.thirdparty.com/lr/', at . I can't figure out how to make Serializer happy and what exactly these two mean

xsi:type="ResponseExt" xmlns="http://www.thirdparty.com/lr/

As always any advice and pointer are appreciated

© Stack Overflow or respective owner

Related posts about c#

Related posts about xmlserializer