0

I have a Java backend es a C# Silverlight UI which are communicating with each other via SOAP XML messages. The message contains a large object which contains lots of smaller objects which contains lots of even smaller objects and so on. My aim is to have two instance of this object on C# side, one that is the original and another one that user can edit. I can achieve it by deep-copying the object on C# side, but is a bit complicated to implement and slow. I can send two same objects in the SOAP XML Message, but it would waste the resources.

Could I load the content of the same SOAP XML messages into two different C# objects which don't point to the same refernce.

Thanks in advance

user2693979
  • 2,482
  • 4
  • 24
  • 23

1 Answers1

0

Sure you can...

var myFirstInstance = MyDeserializeMethod(incomingXML);
var mySecondInstance = MyDeserializeMethod(incomingXML);

Since it is being deserialized first, it is not a direct reference to incomingXML - you are assigning the object which is returned from MyDeserializeMethod, which is a different object every time you run it.

Dave Smash
  • 2,941
  • 1
  • 18
  • 38
  • Thanks for your answer, but I am using attributes for serialization/deserialization. System.Xml.Serialization.XmlElementAttribute(Order=0) Is there a way to write a custom deserializator in this case? – user2693979 Oct 19 '16 at 19:26
  • The easiest way will be to set up classes that model the data you are expecting to receive. Then you can deserialize automatically by creating an XmlSerializer object and calling mySerializer.Deserialize. This will have the same effect as writing a custom method (which you could also do...) Here is an example: http://stackoverflow.com/questions/10518372/how-to-deserialize-xml-to-object – Dave Smash Oct 19 '16 at 19:34