I have a problem with serialisation. The class in question represents a network packet and has an associated byte array for payload, which may be null.
I exposed this using GetData and SetData methods in line with Microsoft Framework Design Guidelines recommendations, because in order to prevent bizarre crosstalk, reading and writing the array entails copying it rather than passing a reference. The guidelines suggest Get/Set when there are significant effects such as object creation, and that’s what I did.
Unfortunately, this has had the consequence that the internal member is not serialised. The member is marked protected. Apart from exposing it as a public property, how can I cause this to be serialised when the object is passed from server to client by a web service?
(edit: assumes web usage; protocol not clear in original question)
Can you use WCF? The
DataContractSerializersupports non-public members:If not, you’ll have to simply consider it a DTO, and make the property public.
Other options – binary serialization? BinaryFormatter is not portable between platforms (so not ideal for all web services), but things like protocol buffers are more friendly. But there is no WDSL support for this, nor any IPC stack (it is raw data only).