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. how to serialzie object to XML and send through Socket ???

how to serialzie object to XML and send through Socket ???

Scheduled Pinned Locked Moved C#
tutorialdata-structuresxmlquestion
3 Posts 3 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.
  • Z Offline
    Z Offline
    zinc_z
    wrote on last edited by
    #1

    Hi, I want to serialize my class object to XML and send through AsynChronous socket. I looked on net and I found an exmaple, it uses FileStreamwriter class to write serialized object to file. I want to use netwrokStream to send to this object to Socket . But in socket's BeginSend() method there is no way to send netwrokstream ... ? there is byte array argument in this method ... Do I need to convert stream class to byet array and send to this to byte[] in BeginSend() method ??? If it so then is there any example to convert to byte[] ??? Thanks, ZINK

    S J 2 Replies Last reply
    0
    • Z zinc_z

      Hi, I want to serialize my class object to XML and send through AsynChronous socket. I looked on net and I found an exmaple, it uses FileStreamwriter class to write serialized object to file. I want to use netwrokStream to send to this object to Socket . But in socket's BeginSend() method there is no way to send netwrokstream ... ? there is byte array argument in this method ... Do I need to convert stream class to byet array and send to this to byte[] in BeginSend() method ??? If it so then is there any example to convert to byte[] ??? Thanks, ZINK

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      You could serialize it to a System.IO.MemoryStream[^] instead and use the ToArray[^] method to get a byte[] array of the memory stream. You could then use the socket method you mentioned to write it out.

      Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

      1 Reply Last reply
      0
      • Z zinc_z

        Hi, I want to serialize my class object to XML and send through AsynChronous socket. I looked on net and I found an exmaple, it uses FileStreamwriter class to write serialized object to file. I want to use netwrokStream to send to this object to Socket . But in socket's BeginSend() method there is no way to send netwrokstream ... ? there is byte array argument in this method ... Do I need to convert stream class to byet array and send to this to byte[] in BeginSend() method ??? If it so then is there any example to convert to byte[] ??? Thanks, ZINK

        J Offline
        J Offline
        johland
        wrote on last edited by
        #3

        if you use SoapFormatter (using System.Runtime.Serialization.Formatters.Soap;) you can do: NetworkStream netStream=new NetworkStream (socket); Object obj=new Object (); SoapFormatter sf = new SoapFormatter(); //Serialize your object with the NetWorkStream sf.Serialize(netStream, obj); //on the receiving side: Object obj= sf.Deserialize(netStream); hope i understood your question and manged to help...

        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