A dumb question: Let’s say I have an object that i store in viewstate. I have it marked as Serializable. I also reuse the same object in my WCF service. But the web service serializes and exposes some internal properties that are not necessary/safe to display to a service client. Is there a way to allow field/property serialization for ViewState but not Web Service? [NonSerialized] hides properties from both.
I know I can implement a POCO for web service use, but I wanted to keep method/object signatures unchanged as far as the class names.
Just wonder if there’s a way. If not, i’m gonna have to either live without those fields in ViewState or create POCOs and let customers worry about reimplementing their clients.
Thanks
Yes, when creating a DataContract for a web service, you mark the members you want to be included in the service requests and replies with the
[DataMember]attribute.Edit: In .NET 4.0 you can also use the [IgnoreDataMember] Attribute to exclude a member from serialization. From Using Data Contracts: