Search code examples
c#xml-serializationprivate-members

Serializing both to local and SOAP with private members c#


Can someone please point me in the right direction? I am trying to serialize some classes for dual use: 1) to save data locally in XML format and 2) to send the classes to a web service using SOAP.

There are some (private) members in the class that I want to save locally, but I do not want them over the wire. Is there a way to do this without having 2 near copies of the same class (one with the private members, and the other without)?

Edit: The point of this post is not to determine which is the best way for me to serialize private members, but to figure out a way to serialize my data locally so I can save the ALL my class information in XML on my local box, and yet still be able to serialize a defined subset of those members so I can pass them through SOAP to a web service.

Hope that makes sense!


Solution

  • I'd recommend using the DataContractSerializer that's what WCF uses for SOAP purposes, and with the DataContract you can decorate private members as participating in serialization

    Here's a good link for DataContract usage http://msdn.microsoft.com/en-us/library/ms733127.aspx