Protogen and wcf json serialization

71 views
Skip to first unread message

Neta Nir

unread,
Jul 15, 2014, 3:30:34 AM7/15/14
to prot...@googlegroups.com
Hello,
We are using Protogen in .Net environment. The  auto generated class from protgen is used as a  response in a service contract between a wcf service (http binding)  and a browser client. WCF uses JSON  serializer, the built in. The problem we are having is that the c# Response class (which is auto generated from protogen) is created with Properties, for example:
    

        [global::System.Serializable, global::ProtoBuf.ProtoContract(Name = @"Response")]
        public partial class Response : global::ProtoBuf.IExtensible
        {
        public Response() { } 
         private bool _success;
        [global::ProtoBuf.ProtoMember(1, IsRequired = true, Name = @"success", DataFormat = global::ProtoBuf.DataFormat.Default)]
        public bool success
        {
            get { return _success; }
            set { _success = value; }
        }

This class is serialized by the WCF default json serializer and returned to the client. The problem is that the json serialize output is composed from the private member of the class and not from the public properties, meaning that the browser response is returned in the following way:
{_success:value} instead of {success:true}.
This is because of the [System.Serializable] tag  on the class which is makes  all of the class  fields serialized  (no properties). 
Is there a way to tell protogen to create the class with only public fields and not properties? Any other suggestion will be welcome as well
Thanks

Marc Gravell

unread,
Jul 15, 2014, 4:34:21 PM7/15/14
to Neta Nir, Protocol Buffers

This is specifically protobuf-net; firstly, you should be able to add -p:lightFramework to the command - that omits a few things that don't work on all frameworks, including [Serializable] iirc.

However, you can also just edit CSharp.xslt to make any necessary changes. Stick it alongside protogen.exe and it should be used automatically.

Marc

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages