Home All Groups Group Topic Archive Search About

Xml serialization over network stream

Author
1 Nov 2006 4:03 PM
Nenad Dobrilovic
Hi,

I am trying to use xml serialization over TCP connection, but I have a
problem...
I created classes using xsd.exe, then I managed to establish a connection
among two clients. This is the code which is executing on the client side:

TcpClient client = new TcpClient(serverIPAddress, serverIPPort);
                using (NetworkStream netStream = client.GetStream())
                {
                    if (netStream.CanWrite)
                    {
                        XmlSerializer serializer = new
XmlSerializer(typeof(command));
                        command commandSend = new command();
                         serializer.Serialize(netStream, commandSend);
                        netStream.Flush();
                        if (netStream.CanRead)
                        {
                            command commandRead =
(command)serializer.Deserialize(netStream);
                         }
                    }
                }
                client.Close();

But, server never manage to deserialize. TcpSpy is showing that data is
sent, and that xml is ok, but server is waiting forever and never do the
deserialization. This is a code:

            using (NetworkStream netStream = client.GetStream())
            {
                if (netStream.CanRead)
                {
                    try
                    {
                        XmlSerializer serializer = new
XmlSerializer(typeof(command));
                        command commandReceived =
(command)serializer.Deserialize(netStream);
                         .... this is place where server never reaches.

If I disconnect the client after serialization is done, server than can read
the data, but, because the connection is closed, it cannot send data back.

Can anyone help me, please?

Best regards,
--
Nenad Dobrilovic

AddThis Social Bookmark Button