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