TcpClient client = new TcpClient(AddressFamily.InterNetwork);
client.SendTimeout = mSvcConfig.Data.SvcTimeout; // 1000
client.Connect( mSvcConfig.Data.SvcAddress, mSvcConfig.Data.SvcPort); //
"localhost", 7024
NetworkStream stream = client.GetStream();
XmlSerializer outserializer = new XmlSerializer(typeof(LinkMessage)); //
my data object, all string/int data
XmlTextWriter tw = new XmlTextWriter( stream, Encoding.UTF8);
outserializer.Serialize(tw, mMsg ); // ref LinkMessage
stream.Flush();
client.Close();
Produces the following output when written via the TcpClient stream (note
extraneous "o;?" at beginning of message):
o;?<?xml version="1.0" encoding="utf-8"?><LinkMessage
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><MessageType>Anchor</M
essageType><InnerText>Client Side ImageMap</InnerText><Href>http:
//www.he.net/~seidel/Map/clientmap.html</Href><ImageSrc /></LinkMessage>
but produces the same output, sans garbage, when the same code writes to an
XmlTextWriter based on a disk file (i.e. - seems like changing only the
stream type results in spurious "Added" output). If the encoding is changed
to Encoding.Unicode, different garbage (?~) prior to the actual message. If
Encoding.ASCII, no garbage - but also wrong encoding in the emitted XML.
What can I do to eliminate this leading junk at the beginning of my
messages? The Java app that is a target for this socket communication can't
handle it...

Signature
Regards,
Jim Allison
jwallison.1@digitalcollimation.com
(de-mung by removing '.1')
Dino Chiesa [Microsoft] - 20 Dec 2004 16:09 GMT
did you try implementing your own XmlTextWriter, and stubbing the
WriteStartDocument() method? Eg,
public class XmlTextWriterFormattedNoDeclaration :
System.Xml.XmlTextWriter {
public XmlTextWriterFormattedNoDeclaration (System.IO.TextWriter w) :
base(w) { Formatting= System.Xml.Formatting.Indented;}
public override void WriteStartDocument () { }
}
?
-Dino
> TcpClient client = new TcpClient(AddressFamily.InterNetwork);
> client.SendTimeout = mSvcConfig.Data.SvcTimeout; // 1000
[quoted text clipped - 35 lines]
> can't
> handle it...