Following situation:
Our software works with business objects, at the moment they are sent with wcf from the server to the 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; }
}
The Problem:
We would like to send DTO's to the client instead of the business object's. I heard, that it is possible to retrieve at the client an instance of a different type than was sent on 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 response would look like this:
[DataContract]
public class Response
{
[DataMember]
public List<ISomeValue> Values { get; set; }
}
On the 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 it with declaring only the known type of the DTO object and with Data Contract Equivalence, but WCF still keep deserializing the item as a BO instance.
I have to add, that both ways have to work, Sending the BO and retrieving it as a BO and sending the BO and retrieving a DTO, but of course with different requests.
So my question is, is this possible and if yes, what am I doing wrong?
Thanks for help, Enyra
Edit: I also found out, that we are using the NetDataSerializer, could that be the problem that it does not work?