How to Serialize ReadOnly Property
From the forum discussion:
"We have class Class1 which has read-only property ID among others. We have WebService with methods public Class1 GetClass1ByID(int id) and public int SetClass1(Class1 c). The question is how to make this configuration work. Explanation. ID property on the client is a database constraint so we can never give a chance to change it. ReadOnly attribute did not help so as adding an empty setter to the property, ISerializable implementation was simply ignored by the WebService. So how we can solve the problem ?"
Microsoft provides 2 workarounds:
- First is "Throwing exception in setter".
- Second is "Using WebMethods instead of setter and getter".
The former looks better, but still does not solve the problem 100%.
Thursday, April 15, 2004 1:46 AM