473,769 Members | 3,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using XMLSerializer to send XML data on a NetworkStream over a socket connection

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

May 17 '07 #1
1 5772
That looks like it should work... did you close the stream after
writing?

Anyways... to investigate, the first thing I would do would be to read
the stream contents into a string (or perhaps an XmlDocument since you
am expecting xml) and double-check what we received at the client.

Marc
May 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4322
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;
4
5413
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...
7
14099
by: Rex Winn | last post by:
I've Googled until my eyes hurt looking for a way to issue Telnet commands from C# and cannot find anything but $300 libraries that encapsulate it for you. I don't want to be able to create a Telnet client. I just need to send a telnet request to a local IP address on a LAN issue a "c" then a "b" and stream back the text for internal use. The "c" changes sub-menus and the "b" is a switch to dump the status of a firewall. I need to issue...
6
3326
by: Ryan | last post by:
Hi, I am confused with how NetworkStream works. My application needs to handle heavy requests sent through TCP socket connection. I use NetworkStream.Read method to get the stream data. The
1
4537
by: hamil | last post by:
I am having trouble using the TcpListener and TcpClient classes. At the end of this post is server code that runs, and a class whose purpose is described below. I need to know when the client closes the connection so I can exit my listener code. Here is what I have tried. First I asked MSDN and they said..
1
7402
by: crashed | last post by:
Hi, I am using C# in .NET 2.0 and im trying to read a stream from a socket. The code works on the first attempt but fails on subsequent attempts. It is in a multithreaded application. It seems the PlayerStream.Read() sets the PlayerSocket.Connected=false??? I am getting the following error: System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly
1
15635
by: verge | last post by:
hello everyone! how's it going? like everyone in here im in need of some help and good friendship along the way...take a look at this: //MODIFIED SO IT DEALS WITH WINDOWS FTP USING ACTIVE CONNECTION //IMPORTANT: the logic is NOT complete, the program works only once and disconnects or freeze //One needs to modify or rewrite the program so it is fully functional for LIST and RETR
5
15726
by: Arno | last post by:
reposted with the right microsoft managed newsgroup ID: Sorry for the inconvinience Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable to read data from the transport connection" when restart reading the stream with socket.BeginRead in the Sub SocketIncomingMsg. I'm debugging now for weeks, but I can't detect where it's
0
1642
by: =?Utf-8?B?T2xpdmllciBHSUw=?= | last post by:
Hello, I try to post an HTTP message containing an XML document, and I get the following exception : System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---System.IO.IOException: Unable to write data to the transport connection: Uma solicitação de envio ou recepção de dados não foi permitida porque o socket não está ligado e (durante o envio num socket de datagrama utilizando...
0
9583
marktang
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...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10039
jinu1996
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...
1
9990
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,...
0
6668
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();...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3955
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.