c# - Generate xml message to send over tcp -


i have classes generated xsd use create xml send on wire. want create document in memory, convert string/byte[] , send it. under impression once classes populated, tostring() , return entire document out. doesn't seem case... doing wrong here?

@event myevent = new @event(); myevent.name = "addprogram"; myevent.version = 8.0m;  datetime mydatetime = new datetime(); mydatetime = datetime.now; myevent.time = mydatetime;  detail mydetail = new detail(); mydetail.name = "program1"  myevent.detail = mydetail;   controller controller = new controller(); controller.actionspecified = true; controller.action = controlleraction.create;  mydetail.controller = controller;  string xmlstring = myevent.tostring();   //this expect string. 

all out of is: "event"

i not sure got information tostring() give xml representation of class not true. should refer article xml serialization.

http://msdn.microsoft.com/en-us/library/58a18dwa(v=vs.110).aspx

if have class of type event need following serialize xml, small tidbit stay away using key words class or variable definitions if @ possible, if you're not in control of hands tied.

@event myevent = new @event(); myevent.name = "addprogram"; myevent.version = 8.0m;  string xmliwant= ""; system.xml.serialization.xmlserializer x = new system.xml.serialization.xmlserializer(@event); using (stringwriter writer = new stringwriter()) {    x.serialize(writer, myevent);    xmliwant = writer.tostring(); } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -