XML Serializer Help
-
Hi there, im working on a little client / server application, and im having trouble sending messages between the two. I can send messages no problem as text, but when I serialize an xml class and send that it gives me an error "There is an error in XML document (6, 16)". Heres the code: MessageClass - this is what is being serialized and submitted //-------------------------------------------- //-------------------------------------------- public class messageClass { public int clientID; public int messageType; public int data; public messageClass() { } } //-------------------------------------------- //-------------------------------------------- SERVER code - this is where the class is declared, filled in and submitted. NOTE: I want "data" to be an object, but ive used int here for debugging. //-------------------------------------------- //-------------------------------------------- Socket listener = (Socket)ar.AsyncState; client = listener.EndAccept(ar); Console.WriteLine("client {0}, joined", client.RemoteEndPoint); // send the user a session ID string strSessionID = sessionID.ToString(); sessionID++; //Byte[] byteSessionID = System.Text.Encoding.ASCII.GetBytes(strSessionID.ToCharArray()); //client.Send(byteSessionID, byteSessionID.Length, 0); messageClass message = new messageClass(); message.clientID = sessionID; message.messageType = 1; message.data = 1; XmlSerializer xml = new XmlSerializer(message.GetType()); MemoryStream transmitStream = new MemoryStream(); xml.Serialize(transmitStream, message); client.Send(transmitStream.GetBuffer()); Console.WriteLine("Sent message"); listener.BeginAccept(new AsyncCallback(OnConnectRequest), listener); //-------------------------------------------- //-------------------------------------------- CLIENT - recieving and decoding message, this is where the error is occuring. Message is recieved but will not parse: //-------------------------------------------- //-------------------------------------------- public void setupRecieveCallback(Socket sock) { try { AsyncCallback recieveD
-
Hi there, im working on a little client / server application, and im having trouble sending messages between the two. I can send messages no problem as text, but when I serialize an xml class and send that it gives me an error "There is an error in XML document (6, 16)". Heres the code: MessageClass - this is what is being serialized and submitted //-------------------------------------------- //-------------------------------------------- public class messageClass { public int clientID; public int messageType; public int data; public messageClass() { } } //-------------------------------------------- //-------------------------------------------- SERVER code - this is where the class is declared, filled in and submitted. NOTE: I want "data" to be an object, but ive used int here for debugging. //-------------------------------------------- //-------------------------------------------- Socket listener = (Socket)ar.AsyncState; client = listener.EndAccept(ar); Console.WriteLine("client {0}, joined", client.RemoteEndPoint); // send the user a session ID string strSessionID = sessionID.ToString(); sessionID++; //Byte[] byteSessionID = System.Text.Encoding.ASCII.GetBytes(strSessionID.ToCharArray()); //client.Send(byteSessionID, byteSessionID.Length, 0); messageClass message = new messageClass(); message.clientID = sessionID; message.messageType = 1; message.data = 1; XmlSerializer xml = new XmlSerializer(message.GetType()); MemoryStream transmitStream = new MemoryStream(); xml.Serialize(transmitStream, message); client.Send(transmitStream.GetBuffer()); Console.WriteLine("Sent message"); listener.BeginAccept(new AsyncCallback(OnConnectRequest), listener); //-------------------------------------------- //-------------------------------------------- CLIENT - recieving and decoding message, this is where the error is occuring. Message is recieved but will not parse: //-------------------------------------------- //-------------------------------------------- public void setupRecieveCallback(Socket sock) { try { AsyncCallback recieveD
Sorry, forgot to tell it not to treat barckets as HTML. Here is the actual XML that is recieved by the client: 2 1 1