When an object is serialized (by remoting to be sent across the wire) does the instance method code get serialized? Or are just the class level instance fields serialized?
I am asking this as some of my objects have large method and want to know wheather I should be using DTO’s (data transfer objects) for sending data across the wire.
I guessing it’s just the data plus some type version data … am I right?
Thanks
Methods are never serialized.
Re “fields” – it all depends on the serializer;
BinaryFormatterwill do fields; you mention “remoting”, which suggestsBinaryFormatter, but remoting is largely a hangover now – from MSDN (on remoting):If you use web-services or WCF:
XmlSerializerdoes public fields+properties;DataContractSerializerwill do marked fields, etc.Regular classes are often reusable as DTOs, but if you need lots of control over the wire (or have versioning issues), a separate DTO can be helpful.
(edit/additional) note also that there are other reasons not to like
BinaryFormatter– it can be very brittle with versioning, and very painful to fix (although achievable). Other (more tolerant) serializers exist if this is likely to be an issue… if so, let me know and I’ll update.