c# - How to deserialize a different interface implementation with wcf -


following situation:

our software works business objects, @ moment sent wcf server client.

[serializable] public class somevaluebo {    public datetime timestamp{ get; set; } } 

they packed in request/response messages.

[datacontract] public class response {   [datamember]   public list<somevaluebo> values { get; set; } } 

the problem:

we send dto's client instead of business object's. heard, possible retrieve @ client instance of different type sent on 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 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 client:

response response = serviceproxy.handlerequest(request); isomevalue value = response.values[0];  value somevaluedto 

i tried declaring known type of dto object , data contract equivalence, wcf still keep deserializing item bo instance.

i have add, both ways have work, sending bo , retrieving bo , sending bo , retrieving dto, of course different requests.

so question is, possible , if yes, doing wrong?

thanks help, enyra

edit: found out, using netdataserializer, problem not work?

from msdn:

the netdatacontractserializer differs datacontractserializer in 1 important way: netdatacontractserializer includes clr type information in serialized xml, whereas datacontractserializer not. therefore, netdatacontractserializer can used if both serializing , deserializing ends share same clr types.

that's why it's not working @ present.

if use datacontractserializer instead, client , service need agree on serialized xml representation of object state, not on exact clr runtime type. you'll need attribute both sides' types datacontractattribute in order xml namespace associated serialized representation same on both sides. , data contracts have equivalent in terms of serialized structure.

that said, trying should workable datacontractserializer. whether it's best way go - design decisions "it depends".


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -