Home
Find the answer to your question
How to de-serialize response payload received using .NET framework.
The following is the code sample for converting the payload to an object using C#.NET
Code in the Program.cs file |
private void button1_Click(object sender, EventArgs e) { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(textBox1.Text.Trim()); XmlNode nodeList = xmlDoc.SelectSingleNode(@".//*[local-name(.)='GetItemTransactionsResponse']"); nodeList.Attributes.RemoveAll(); string xmlStr = nodeList.OuterXml.Replace("GetItemTransactionsResponse", "GetItemTransactionsResponseType"); GetItemTransactionsResponseType res = (GetItemTransactionsResponseType)DeserializeObject(xmlStr); label2.Text = "ItemID: " + res.Item.ItemID; label3.Text = "Title: " + res.Item.Title; } catch (Exception ex) { throw ex; } } private object DeserializeObject(string xmlStr) { GetItemTransactionsResponseType responseObj = new GetItemTransactionsResponseType(); StringReader read = new StringReader(xmlStr); XmlSerializer serializer = new XmlSerializer(responseObj.GetType(), strNamespace); XmlReader reader = new XmlTextReader(read); try { responseObj = (GetItemTransactionsResponseType)serializer.Deserialize(reader); return responseObj; } catch (Exception ex) { throw ex; } finally { reader.Close(); read.Close(); read.Dispose(); } }
|
Note:
Please see the attachment for a sample windows application which converts GetItemTransactions SOAP payload to a GetItemTransactionsResponseType object.