0

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.

user819774
  • 1,456
  • 1
  • 19
  • 48
  • I generate a new respond without List, but I still got the error. It looks like the app didn't find the class. Error message:Error in line 2 position 2. Expecting element 'Call' from namespace 'http://schemas.datacontract.org/2004/07/CMSPhoneApp.DataObjects'.. Encountered 'Element' with name 'Call', namespace 'http://schemas.datacontract.org/2004/07/DataObjects'. I already build the new project "DataObjects project" using VS2010 Express for windows Phone and then add it as reference. Please help I have stucked in a few days. – user819774 Aug 15 '12 at 17:24
  • Another opiton is create a new project and name it as "DataObjects" with all the classes on the VS 2010 Expression for Windows Phone. – user819774 Aug 23 '12 at 15:18

1 Answers1

0

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.

user819774
  • 1,456
  • 1
  • 19
  • 48