Why the serialize behavior is difference in simulator and iPad device in monotouch?
I have declare the serialize behavior is UTF-8, but when send the serialize data from ipad device to WCF service, I trace the message, it change to ascii, why? (and in simulator it’s OK with UTF-8)
trace in simulator/Chinese Language:
< ?xml version=”1.0″ encoding=”utf-8″? >
…
trace in iPad device/Chinese Language:
< ?xml version=”1.0″ encoding=”us-ascii”? >
…
btw, I serialize the data manually with my static method: XmlSerialize.
public static string XmlSerialize<T>(T obj)
{
using (MemoryStream ms = new MemoryStream())
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
serializer.Serialize(ms, obj);
ms.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(ms, Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
}
public static T XmlDeserialize<T>(string xmlOfObject) where T : class
{
using (MemoryStream ms = new MemoryStream())
{
using (StreamWriter sr = new StreamWriter(ms, Encoding.UTF8))
{
sr.Write(xmlOfObject);
sr.Flush();
ms.Seek(0, SeekOrigin.Begin);
XmlSerializer serializer = new XmlSerializer(typeof(T));
return serializer.Deserialize(ms) as T;
}
}
}
You need to setup
XmlSerializerto use utf-8 as well:Otherwise it will use the default encoding, whatever that happens to be.