Take string received from Web Service and populate class
I have a file of classes 开发者_StackOverflow社区that I generated from an xsd file using the XSD Tool. I receive an XML string response from a web service. How do I populate the generated classes with the string xml received?
You can use System.Runtime.Serialization.DataContractSerializer to generate the class.
TheClass result = null;
DataContractSerializer dcs = new DataContractSerializer(typeof(TheClass));
using(StringReader reader = new StringReader(xml))
{
using(XmlReader XmlReader = new XmlReader(reader))
{
result = dcs.ReadObject() as TheClass;
}
}
精彩评论