XML Serialization of several objects over NetworkStream

K

Kitto

I ran into a serious problem and couldn't find any help on the web:

I want to XML serialize several objects and send them over a
NetworkStream. The serialization for a single objects works fine and
the client can deserialize it without any problems but as soon as
there is more than one object it fails on the second one, telling me
that the root element is missing or wrong.

In my opinion that's happening because XMLWriter doesn't insert a
valid linbreak after the first objects.

Here's the code of the serialization part:

XmlSerializer xs = new XmlSerializer(maritimeObject.GetType());
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.ConformanceLevel = ConformanceLevel.Auto;
settings.OmitXmlDeclaration = true;
settings.CloseOutput = false;
settings.Encoding = Encoding.UTF8;
XmlWriter xmlWriter = XmlWriter.Create(stream, settings);
xs.Serialize(xmlWriter, maritimeObject);
xmlWriter.Close();

Deserialize is simply a call to the Deserialize method of an
XmlSerializer.

Here's a snippet of the Xml:

</attributes>
</MaritimeObject><?xml version="1.0" encoding="utf-8"?>
<MaritimeObject>
<mmsi>319307000</mmsi>
<attributes>

I would be really glad and thankful if somebody could help.

Christoph
 
S

sloan

See
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!114.entry

I ran into a serious problem and couldn't find any help on the web:

I want to XML serialize several objects and send them over a
NetworkStream. The serialization for a single objects works fine and
the client can deserialize it without any problems but as soon as
there is more than one object it fails on the second one, telling me
that the root element is missing or wrong.

In my opinion that's happening because XMLWriter doesn't insert a
valid linbreak after the first objects.

Here's the code of the serialization part:

XmlSerializer xs = new XmlSerializer(maritimeObject.GetType());
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.ConformanceLevel = ConformanceLevel.Auto;
settings.OmitXmlDeclaration = true;
settings.CloseOutput = false;
settings.Encoding = Encoding.UTF8;
XmlWriter xmlWriter = XmlWriter.Create(stream, settings);
xs.Serialize(xmlWriter, maritimeObject);
xmlWriter.Close();

Deserialize is simply a call to the Deserialize method of an
XmlSerializer.

Here's a snippet of the Xml:

</attributes>
</MaritimeObject>?<?xml version="1.0" encoding="utf-8"?>
<MaritimeObject>
<mmsi>319307000</mmsi>
<attributes>

I would be really glad and thankful if somebody could help.

Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top