0
votes

a few days ago i posted a question about Serializing the ResponseStatus property with BinaryFormatter. Mythz pointed out it wasnt the fastest way to go, so i decided to switch to another formatter. Tried ProtoBuff and MsgPack, and am on ProtoBuf now.

My real question is: im trying to grasp how Protobuf knows how ServiceStack Dto's should be serialized. I tried adding all the possible attributes to my existing dto, ProtoContract and ProtoMember(0,1,2,3,etc), but also DataContract and DataMember.

On top of that i dont use ServiceStack's own client, but try to serialize the request to an existing stream.

If i dont do this:

ServiceStack.ProtoBuf.ProtoBufFormat.Model.Add (typeof(NameSpacePlaceholder.Service.Dto.GetNodes), false);

i get an error about Types and Contracts that cannot be infered, If i do add that piece of code, all continues great, but the deserialized object is empty.

Im using this to Serialize:

ServiceStack.ProtoBuf.ProtoBufFormat.Model.Serialize (ms, myObject);

and to Deserialize:

ServiceStack.ProtoBuf.ProtoBufFormat.Model.Deserialize (ms, null, deserializationType);

I think im missing something here. Could it have something to do with namespaces? I looked into some code from ServiceStack.ProtoBuff, it isnt so hard to understand, but i cannot get it going.

Things that are unclear to me now:

  1. Is there a need to add Attributes to the existing DTO's ? (in ProtoBuf V2 i can also do it in code, i read, but for now i can also alter the existing DTO's)
  2. Do i need to initialize the Request(and response) DTO's, in my Client(Serialize) as wel in my Server(Deserialize)
  3. Is there some reason why i should not be serializing to my own Stream ?

Many thanks,

1

1 Answers

0
votes

I hate it to post an answer myself, it means i havent searched enough in the first place

I learned the following attributes are very important:

  1. [ProtoContract]
  2. [ProtoMember(X)]
  3. [ProtoInclude(X,typeof(DerivingClass))]

For now i learned something new: why class inheritance in DTO's is not advisable.

I've got it going now, and will try to make it real-life friendly..