Converting REST response using XmlSerializer?
missamo80
Registered Users Posts: 43 Big grins
Does anyone have sample code for taking a REST response and converting it to .NET objects using XmlSerializer? I thought it would be straightforward, but since the response starts with an rsp <?rsp>tag instead of an xml <?xml>tag, the default .NET serializer barfs saying it's not valid XML.
Neil
Neil
0
Comments
I am pretty sure that the root element doesn't need to be an xml tag.
The response contains the correct xml header... I don't currently have a version of .net available to confirm this. Are able to try writing a response to a file manually, then attempting to load the response that way using the Xml Serializer just to rule out that there is nothing else going on.
Cheers,
David
SmugMug API Developer
My Photos
My .NET object is called "LoginResponse". But the response that comes back via REST always uses "rsp" as the starting tag. So .NET barfs when it tries to deserialize, because the object names don't match. If I change my object name from "LoginResponse" to "rsp" then everything works fine.
This is, of course, useless, since I can't have every object in my app called "rsp". Sigh.
Neil
I handle the issue by just manually drilling thru the rsp node of the XML and serialising from there.
I hope to release the source to my smugmug .net dll that I am writing when it is closer to working, but here is a bit of code i hacked together to show the general way I handle this.
Hope this helps someone.