Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. XML Serializer Help

XML Serializer Help

Scheduled Pinned Locked Moved C#
helpsysadminxmlquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • L Lost User

      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

      G Offline
      G Offline
      Gavin Coates
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups