Happy new year everyobdy, After I serialize object using StringWriter and return output response and send to client. But when client receive the response: It has a tag like this:
<string xmlns="http://schemas.microsoft.com/...">
<?xml version="1.0" encoding="utf-16">
<trx>.....</trx>
</string>
So, my questions are: 1. How should I return the correct format xml like below:
<?xml version="1.0" encoding="utf-16">
<trx>.....</trx>
2. If I send the response as byte[] using MemoryStream, does the client receive correct with encoding="utf-8" ?
Thank you so much! This is the code path I used for serializing:
StringWriter textWriter = new StringWriter();
XmlWriter tw = null;
XmlWriterSettings settings new XmlWriterSettings{
Encoding =UnicodeEncoding.UTF8,
Indent =false,
OmitXmlDeclaration =false
};
var serialize1 =new XmlSerializer(typeof(OTrx));
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("","");
tw=XmlWriter.Create(textWriter,settings);
serializer1.Serialize(tw,oTrx,ns);
var output=textWriter.ToString();
return output