zling2001 / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Deserialization does not conform to WCF contract standards #369

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
First of all, thanks for this library. It really provides a huge performance 
increase compared to the DataContractSerializer within WCF.  

What steps will reproduce the problem?
1. Define a WCF contract class and add the [ProtoContract] [ProboMember] 
accordingly
2. Within the contract class, define a constructor that sets the default values 
of all members
3. Send an object of this contract class over the wire via WCF

What is the expected output? What do you see instead?

It is expected, that the constructor of the contract class is NOT executed when 
retrieving and deserializing a message. See 
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/48f608e1-749c-4b7c-9c81
-612d6f89716d

However because the constructor is executed, the process of deserialization 
"destroys" that data within the message. This makes it impossible to transfer 
data over the wire using protobuf-net. (It would require to refactor all 
contracts and move default-value-logic somewhere else)

What version of the product are you using? On what operating system?
.NET 4.5, protobuf-net r622

    [DataContract]
    [ProtoContract]
    public class EntryProductProperty : ProductPropertyBase
    {
        public EntryProductProperty()
        {
            X = 0; // this must NOT be executed during serialization to conform to the default WCF behavior. Otherwise X cannot be transferred over the wire.
        }

        [DataMember]
        [ProtoMember(1)]
        public string X { get; set; }

Original issue reported on code.google.com by adi.he...@gmail.com on 10 Apr 2013 at 11:27

GoogleCodeExporter commented 9 years ago
Different serialization technologies take different decisions here. 
Protobuf-net gives you the choice. Change to:

    [ProtoContract(SkipConstructor=true)]

and it'll work as you intend.

Original comment by marc.gravell on 10 Apr 2013 at 11:52

GoogleCodeExporter commented 9 years ago
Awesome, thanks

Original comment by adi.he...@gmail.com on 10 Apr 2013 at 12:09

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 10 Apr 2013 at 12:20