The following situation:
Our software works with business objects, currently they are sent from wcf from server to client.
[Serializable] public class SomeValueBO { public DateTime Timestamp{ get; set; } }
They are packed in request / response messages.
[DataContract] public class Response { [DataMember] public List<SomeValueBO> Values { get; set; } }
Problem:
We want to send the DTO to the client instead of the business object. I heard that on the client you can get an instance of another type that was sent to the server.
Example:
public interface ISomeValue { DateTime Timestamp { get; set; } } [Serializable] public class SomeValueBO : ISomeValue { public DateTime Timestamp { get; set; } } [DataContract] public class SomeValueDTO : ISomeValue { [DataMember] public DateTime Timestamp { get; set; } }
The answer will look like this:
[DataContract] public class Response { [DataMember] public List<ISomeValue> Values { get; set; } }
On server:
public class ServiceClass : IService { public Response HandleRequest(Request request) { Response response = new Response(); response.Values.Add(new SomeValueBO()); return response; } }
On the client:
Response response = serviceProxy.HandleRequest(request); ISomeValue value = response.Values[0]; value is SomeValueDTO
I tried this with the declaration of only the known DTO object type and equivalent data equivalence, but WCF still retains the deserialization of the element as an instance of BO.
I need to add that both paths should work by sending BO and retrieving them as BO, and sending BO and retrieving DTO, but of course with different requests.
So my question is: is this possible, and if so, what am I doing wrong?
Thanks for the help, Enyra
Edit: I also found out that we are using NetDataSerializer, maybe the problem is that it does not work?