I have just been fighting a problem for a great amount of time in WCF whereby a custom object of mine was not being sent across the wire in WCF. Actually let me re-phrase, the object was being sent, instantiated, but all properties were empty.
I did an isolated test, instantiated the object, populated only one property in my custom object with a smiple value (“99″), sent it across the wire to the WCF client, and the value was “0″.
VERY STRANGE.
After trying everything and clutching at straws, I removed my class attributes from:
[DataContract]
[Serializable]
public partial class Client { ... }
to:
[Serializable]
public partial class Client {...}
and voilà, it worked. My object was being passed with values populated correctly.
SO WHAT WE LEARNT TODAY
It appears you cannot mark a Data Contract class in use for WCF with both these attributes in conjunction with each other. Because I am relatively new to WCF, <1 year this may be perfectly valid, who knows.
However the interesting point is, this appears to be a new “feature” since the .NET 3.5 Service Pack 1 update, as a friend who is using pre-SP1 utilises both these attributes in production with no problems. Sigh, I always get the weird ones.
So there you have it, and as to why I used both attributes; the reason being is due to some xml serialization I had to perform later on in the client UI, but just marking with Serializable alone as stated works a treat.
Thanks WCF!
See my rant here for further details: http://stackoverflow.com/questions/493827/custom-object-returning-as-empty-from-wcf/
2 Comments
Did you set the [DataMember] attribute for the properties that you wanted sent to the client?
Thx TH.
Run into the same Problem, except for: I dont use [Serializable] because its obsolete with WCF and a [DataContract].
I Added the [DataMember] Attribute and everything works fine.
Post a Comment