Hi,
I want to send XML data from a server to some clients over a network
connection using the TCP/IP protocol. If I send the XMLs as byte
arrays I need to insert header information in the data to distinguish
the XMLs from each other in the stream of data. Is there any way to
avoid this (for instance by sending SOAP telegrams))?
I have tried using the XMLSerializer.S erialize(stream ) to serialize
the XML telegrams and send them over the socket connection but when I
want to use the XMLSerializer.D eserialize(stre am) to read the sent
telegrams it either newer finishes or returns a xml parse error.
//Send the XML
ShoppingList myList = new ShoppingList();
myList.AddItem( new ShoppingItem("e ggs", 1.49));
myList.AddItem( new ShoppingItem("g round beef", 3.69));
myList.AddItem( new ShoppingItem("b read", 0.89));
XmlSerializer s = new XmlSerializer(t ypeof(ShoppingL ist));
stream = new NetworkStream(m _socWorker);
s.Serialize(str eam, myList);
//Receive the XML
// Deserialization
ShoppingList newList;
XmlSerializer s = new XmlSerializer(t ypeof(ShoppingL ist));
newList = (ShoppingList)s .Deserialize(st ream);
What am I doing wrong? Will the Deserialize() method be able to
separate the XML telegrams in the stream automatically?
Best regards,
Kim 3 3294
Unfortunately, no. What you should do is before each serialized type
you want to send, send the length of the XML document you are going to send.
Then, on the other side, take note of the length, and only read that much
into a byte array, or something of the sort, and then pass that to the
XmlSerializer. Finally, repeat for all other instances.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
<ki***********@ gmail.comwrote in message
news:11******** **************@ e65g2000hsc.goo glegroups.com.. .
Hi,
I want to send XML data from a server to some clients over a network
connection using the TCP/IP protocol. If I send the XMLs as byte
arrays I need to insert header information in the data to distinguish
the XMLs from each other in the stream of data. Is there any way to
avoid this (for instance by sending SOAP telegrams))?
I have tried using the XMLSerializer.S erialize(stream ) to serialize
the XML telegrams and send them over the socket connection but when I
want to use the XMLSerializer.D eserialize(stre am) to read the sent
telegrams it either newer finishes or returns a xml parse error.
//Send the XML
ShoppingList myList = new ShoppingList();
myList.AddItem( new ShoppingItem("e ggs", 1.49));
myList.AddItem( new ShoppingItem("g round beef", 3.69));
myList.AddItem( new ShoppingItem("b read", 0.89));
XmlSerializer s = new XmlSerializer(t ypeof(ShoppingL ist));
stream = new NetworkStream(m _socWorker);
s.Serialize(str eam, myList);
//Receive the XML
// Deserialization
ShoppingList newList;
XmlSerializer s = new XmlSerializer(t ypeof(ShoppingL ist));
newList = (ShoppingList)s .Deserialize(st ream);
What am I doing wrong? Will the Deserialize() method be able to
separate the XML telegrams in the stream automatically?
Best regards,
Kim
Thank you for your answer.
I am a bit disappointed that the XMLSerializer.D eserialize(Stre am)
method is actually more or less useless when trying to read from a
Networkstream. It would be nice to have a some sort of class that you
could just wrap around the whole thing and then you could send the
objects from one computer and receive the objects on another computer
as an object array without having to worry about separating the data.
Best regards,
Kim Therkelsen
On 17 Maj, 22:58, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
Unfortunately, no. What you should do is before each serialized type
you want to send, send the length of the XML document you are going to send.
Then, on the other side, take note of the length, and only read that much
into a byte array, or something of the sort, and then pass that to the
XmlSerializer. Finally, repeat for all other instances.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om
<kimtherkel...@ gmail.comwrote in message
news:11******** **************@ e65g2000hsc.goo glegroups.com.. .
Hi,
I want to send XML data from a server to some clients over a network
connection using the TCP/IP protocol. If I send the XMLs as byte
arrays I need to insert header information in the data to distinguish
the XMLs from each other in the stream of data. Is there any way to
avoid this (for instance by sending SOAP telegrams))?
I have tried using the XMLSerializer.S erialize(stream ) to serialize
the XML telegrams and send them over the socket connection but when I
want to use the XMLSerializer.D eserialize(stre am) to read the sent
telegrams it either newer finishes or returns a xml parse error.
//Send the XML
ShoppingList myList = new ShoppingList();
myList.AddItem( new ShoppingItem("e ggs", 1.49));
myList.AddItem( new ShoppingItem("g round beef", 3.69));
myList.AddItem( new ShoppingItem("b read", 0.89));
XmlSerializer s = new XmlSerializer(t ypeof(ShoppingL ist));
stream = new NetworkStream(m _socWorker);
s.Serialize(str eam, myList);
//Receive the XML
// Deserialization
ShoppingList newList;
XmlSerializer s = new XmlSerializer(t ypeof(ShoppingL ist));
newList = (ShoppingList)s .Deserialize(st ream);
What am I doing wrong? Will the Deserialize() method be able to
separate the XML telegrams in the stream automatically?
Best regards,
Kim- Skjul tekst i anførselstegn -
- Vis tekst i anførselstegn -
On May 18, 9:31 am, "kimtherkel...@ gmail.com"
<kimtherkel...@ gmail.comwrote:
Thank you for your answer.
I am a bit disappointed that the XMLSerializer.D eserialize(Stre am)
method is actually more or less useless when trying to read from a
Networkstream. It would be nice to have a some sort of class that you
could just wrap around the whole thing and then you could send the
objects from one computer and receive the objects on another computer
as an object array without having to worry about separating the data.
Best regards,
Kim Therkelsen
On 17 Maj, 22:58, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
Unfortunately, no. What you should do is before each serialized type
you want to send, send the length of the XML document you are going to send.
Then, on the other side, take note of the length, and only read that much
into a byte array, or something of the sort, and then pass that to the
XmlSerializer. Finally, repeat for all other instances.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om
<kimtherkel...@ gmail.comwrote in message
news:11******** **************@ e65g2000hsc.goo glegroups.com.. .
Hi,
I want to send XML data from a server to some clients over a network
connection using the TCP/IP protocol. If I send the XMLs as byte
arrays I need to insert header information in the data to distinguish
the XMLs from each other in the stream of data. Is there any way to
avoid this (for instance by sending SOAP telegrams))?
I have tried using the XMLSerializer.S erialize(stream ) to serialize
the XML telegrams and send them over the socket connection but when I
want to use the XMLSerializer.D eserialize(stre am) to read the sent
telegrams it either newer finishes or returns a xml parse error.
//Send the XML
ShoppingList myList = new ShoppingList();
myList.AddItem( new ShoppingItem("e ggs", 1.49));
myList.AddItem( new ShoppingItem("g round beef", 3.69));
myList.AddItem( new ShoppingItem("b read", 0.89));
XmlSerializer s = new XmlSerializer(t ypeof(ShoppingL ist));
stream = new NetworkStream(m _socWorker);
s.Serialize(str eam, myList);
//Receive the XML
// Deserialization
ShoppingList newList;
XmlSerializer s = new XmlSerializer(t ypeof(ShoppingL ist));
newList = (ShoppingList)s .Deserialize(st ream);
What am I doing wrong? Will the Deserialize() method be able to
separate the XML telegrams in the stream automatically?
Best regards,
Kim- Skjul tekst i anførselstegn -
- Vis tekst i anførselstegn -
Hi,
If you can manage both sides of the application, I would suggest using
Web Services Enhancements SOAP messaging over tcp.
If not, Nich just pointed the solution for you.
Cheers,
Moty This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stuart Robertson |
last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not create duplicate XML representations of the shared object, but instead use IDREFs to refer to the shared object.
The XML I'm trying to produce is as follows (where "href" is an IDREF):
<?xml version="1.0" encoding="utf-8"?>
<MyRootClass...
|
by: Bluetears76 |
last post by:
Hi I have a hirachy of classes which are Message(base), then
FileMessage and ChatMessage (extended)
I want to serialize the objects and when i am deserizaling i dont know
if i am getting FileMessage or ChatMessage. So how to get that object
and use it
I have written following code for serialization
public void Send(Message message)
{
NetworkStream netWorkStream=null;
|
by: Anthony Bouch |
last post by:
Hi
I've been reading using the XmlSerializer with custom collections.
I've discovered that when serializing a custom collection (a class that
implements ICollection, IList etc.) the XmlSerializer will only serialize
the collection items - with the default root as ArrayofMyItems etc.
My custom collection class has some additional public properties that I
would like to include in the serialization above the items element array (in
|
by: Loui Mercieca |
last post by:
Hi,
I have created a class, named FormField , which basically contains two
fields, name and value. I have set the tag before the class and the field is set as an
XmlAttribute whil the name as XmlText.
In my main class, i have created an arraylist which contains a collection of
this class FormField. Basically its:
public void Add( string sName, string sValue )
|
by: SJD |
last post by:
I've just read Christoph Schittko's article on XmlSerializer:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp
. . . and very informative it is too.
I, too, am getting nasty FileNotFound exceptions. I've read, and
digested the article, and I think I've found a bug -- it's difficult to
track, though it does happen often.
| |
by: Steve Long |
last post by:
Hello,
I hope this is the right group to post this to. I'm trying to serialize a
class I've written and I'd like to be able to serialze to both binary and
xml formats. Binary serialization is working fine but when I try to
instantiate an XmlSerializer object with:
Dim xmls As New XmlSerializer(GetType(CLayerDefinition))
I get the following error:
|
by: William Stacey [MVP] |
last post by:
Had a method that got some string info from mp3 tags in N files and
serializes this class and deserializes at other side. Works ok except
sometimes get chars that choke the XmlSerializer. After some digging, I
found XmlSerializer chokes on 0x03 chars. It probably chokes on many
others, but this one I found. It serializes ok, but chokes on deserialize
on "<Field1></Field1>". So the questions are:
1) Why does serializer produce...
|
by: Ultrakorne |
last post by:
hi, i have some problems with my client talk to my server...
i am using xmlserializer to serialize object and send them to the other
side of the connection. I need to send / recive by both client and
server. client after login waits all the time listening for objects on a
thread, and sends objects on users events on the main thread. server
waits connections, start a new thread for each connection and after
validating login waits for...
|
by: kimtherkelsen |
last post by:
Hi,
I want to send XML data from a server to some clients over a network
connection using the TCP/IP protocol. If I send the XMLs as byte
arrays I need to insert header information in the data to distinguish
the XMLs from each other in the stream of data. Is there any way to
avoid this (for instance by sending SOAP telegrams))?
I have tried using the XMLSerializer.Serialize(stream) to serialize
the XML telegrams and send them over the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |