0

In my use case i have to use the same model as response for my WCF service and in the same time i have to cache it into redis.

Just part of this object has to be serialized for the WCF response, while the whole object has to be stored into the Redis cache.

Redis uses the decoration [Serializable] while the WCF the [DataContract] which allows me to select the property i want to serialize.

[Serializable]
[DataContract]
public Model {
    [DataMember (Name = "prop1")]
    public string property1 {get; set;}

    [DataMember (Name = "prop2")]
    public  property2 {get; set;}

    [DataMember (Name = "prop3")]
    public  property3 {get; set;}
    public  property4 {get; set;}
    public  property5 {get; set;}
}

What i would like to get is : prop1, prop2, prop3 for the wcf response while i would put the whole object inside redis. What i currently get is an exception from redis which cannot read some properties:

        $exception  {"Unable to read the cache object with key 'userfiltered_323041' before the timeout."}  System.TimeoutException
all public members must mark DataMemberAttribute or IgnoreMemberAttribute. type: MyType member:MyTypeName

Is it possible to instruct Redis to use one serializer and the WCF another one?

  • *What i currently get is an exception from redis which cannot read some properties* - then can please [edit] your question to share the full `ToString()` output of the exception including the exception type, message, traceback and inner exception(s) if any? Also, can you share the code that shows you are storing to redis? – dbc Aug 01 '19 at 19:17
  • added the update – Alessio Orlando Aug 02 '19 at 10:24
  • What are you using to serialize your type, that throws the exception? Some googling suggests it might be `MessagePackSerializer.Serialize` from https://github.com/neuecc/MessagePack-CSharp; is that correct? Because these issues seem similar to yours: https://github.com/neuecc/MessagePack-CSharp/issues/412 and https://github.com/neuecc/MessagePack-CSharp/issues/181#issuecomment-366791738. If so can you share a [mcve] that demos the problem? Should the question be tagged with [tag:msgpack]? – dbc Aug 02 '19 at 11:01
  • the serializer should be the NewtonSoft.Json ... about the use case is exactly what i reported there. You can try to write an istance of that Type into redis and to read all its property... and then you can use the same type in a simple json response from a WCF service. – Alessio Orlando Aug 02 '19 at 12:38
  • [tag:redis] itself doesn't know anything about data contract attributes. You must be using some .Net client like [tag:stackexchange.redis] to communicate with it. What client library are you using? Json.NET never throws the exception you show so something else must be throwing it. That being said, if you are somehow using Json.NET to communicate with [tag:redis], see [Configure JSON.NET to ignore DataContract/DataMember attributes](https://stackoverflow.com/q/11055225/3744182). – dbc Aug 02 '19 at 18:13
  • yes of course i m using a client. I m using Stackexchange. but i still need to serialize some property for the WCF and the overall object for Redis... so stackexchange – Alessio Orlando Aug 03 '19 at 19:18

0 Answers0