I need to convert my web application to phone application. I was succeed to deserializer the request respond into the generic list on my web app, but I haven't figure out how to do it on the phone app. On the web I can use DataContractSerializer and XmlDictionaryRead.CreateTextReader and System.Xml.XmlDictionaryReaderQuotas(), but there is no such method on Windows phone. I modified the code and get the error like that
Error in line 1 position 2. Expecting element 'ArrayOfQueueItem' from namespace 'http://schemas.datacontract.org/2004/07/CMSPhoneApp.DataObjects'.. //Encountered 'Element' with name 'QueueItem', namespace ''.
There is the code to deserialzier
try{
using (XmlReader r = XmlReader.Create(new StringReader(content)))
{
var ser = new DataContractSerializer(typeof(T));
var reader = XmlDictionaryReader.CreateDictionaryReader(r);
ser = new DataContractSerializer(typeof(T));
var deserializedItem = (T)ser.ReadObject(reader, true);
reader.Close();
return deserializedItem;
}
}
I read the respond stream into the string as below:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfQueueItem xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DataObjects">
<QueueItem>
<callNumber>349551</callNumber>
<errorMsg
i:nil="true" />
<link>/Call/349551</link>
<page>Call</page>
<siteCity>Burnaby</siteCity>
<status>Open</status>
<summary>Mobile Application Research</summary>
</QueueItem>
<QueueItem>
<callNumber>376209</callNumber>
<errorMsg
i:nil="true" />
<link>/Call/376209</link>
<page>Call</page>
<siteCity>Burnaby</siteCity>
<status>Open</status>
<summary>July 2012 ASD Calls of the Month.</summary>
</QueueItem>
</ArrayOfQueueItem>
The following is the "QueueItem" class:
namespace CMSPhoneApp.DataObjects
{
//This is Model
public class QueueItem
{
public string callNumber { get; set; }
public string summary { get; set; }
public string status { get; set; } //queInvoiceAdmin no status
public string link { get; set; }
public string errorMsg { get; set; }
public string page { get; set; }
public string siteCity { get; set; }
}
}
Even I trid to cut the respond stream into as follows, I stil got the same error:
<QueueItem>
<callNumber>349551</callNumber>
<errorMsg
i:nil="true" />
<link>/Call/349551</link>
<page>Call</page>
<siteCity>Burnaby</siteCity>
<status>Open</status>
<summary>Mobile Application Research</summary>
</QueueItem>
<QueueItem>
<callNumber>376209</callNumber>
<errorMsg
i:nil="true" />
<link>/Call/376209</link>
<page>Call</page>
<siteCity>Burnaby</siteCity>
<status>Open</status>
<summary>July 2012 ASD Calls of the Month.</summary>
</QueueItem>
Would someone guide me or show me the example or link to solve this problem. Thanks in advance.
It may not be a good solution, but it fix my issue. I changed the 'schemas.datacontract.org/2004/07/DataObjects' to 'schemas.datacontract.org/2004/07/CMSPhoneApp.DataObjects'. Therefore it can find the class location. Also I need to create ArrayOfQueueItem Class for deserialization.