Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / December 2004

Tip: Looking for answers? Try searching our database.

Object serialization and NetworkStream - extraneous characters in output

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jwallison - 08 Dec 2004 14:16 GMT
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...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.