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….