For what reason(s) should WCF return me a "empty" instantiated object when it was clearly populated on my WCF service return before it went over the wire?
For instance a simple OperationContract
method:
response.Client = new Client();
response.Client.ID = 99;
return response;
returns an "empty" Client object (on the client receiving end) and all fields are either null or zero. However just before the response, if I inspect response.Client.ID it is populated with 99?
Just to make matters worse, I have an error object and I populate as such:
response.Errors.Add(new CodedError(Errors.ErrorCodes.LOGIN_AUTHENTICATION_ERROR));
However I CAN see the Error list on the receiving end with this?
If anyone encounters this problem, I have found the fix. Due to business requirements I had marked my custom class with both [Serializable]
and [DataContract]
, this appears to be illegal possibly as of .NET 3.5 SP1?
I have a friend who is sending WCF objects with both these attributes pre .NET 3.5 SP1 and it is working fine. Interesting.
FYI, I simply used [Serializable]
only and it is sending through my object graph correctly. I needed this for xml serialization down the track.
This was a painful issue but glad it is now finally functioning....
Is your object marked as [Serializable] or is it a [DataContract]? You need to mark your object as one or the other.
WCF only knows how to pass primitives or serializable objects across the wire.
Is the client proxy up to date? I've seen it happen when the contract changes and the client is not updated to reflect the change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With