[jdev] SASL debugging
Norman Rasmussen
norman at rasmussen.co.za
Sat Dec 10 16:42:53 CST 2005
Trying to get an object serialized into a utf-8 xml string _without_
the 0xfeff header.
public static string GetStringFromObject(object Object, Type Type) {
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms, Encoding.UTF8);
XmlTextWriter xw = new XmlTextWriter(sw);
xw.Formatting = Formatting.Indented;
XmlSerializer serializer = new XmlSerializer(Type);
serializer.Serialize(xw, Object);
return Encoding.UTF8.GetString(ms.ToArray()).TrimStart('\xfeff');
}
if I tried it any other way, then either the xml would be labeled as
utf-16 (when it was actually utf-8/ascii - who knows because it all
happened to be 7-bit clean) and the web service would bitch, or it
would be utf-16 and the web service would bitch, or I managed to get
utf-8 encoding (and the xml header said it was utf-8), but the web
service I was sending the string to would choke on the utf-8 leader.
On 12/10/05, David Waite <dwaite at gmail.com> wrote:
> > As you found, sometimes the .net framework actually does a utf-16
> > encoding when you ask it for utf-8. This has nailed me recently when
> > trying to use webservices. I ended up having to add and remove the
> > 'marker' bytes (0xff, 0xfe) at the front of the byte array to get it
> > to work properly.
>
> Are you encoding using the io framework rather than the text encoding framework?
>
> -David Waite
>
--
- Norman Rasmussen
- Email: norman at rasmussen.co.za
- Home page: http://norman.rasmussen.co.za/
More information about the JDev
mailing list