bigstupidx / protobuf-net

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

Does not support array for WCF #296

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Protobuf does not support a simple array, but List<T> supported without any 
problems.

What steps will reproduce the problem?
1. implement service with method Foo[] GetFoos() marked by [OperationContract, 
ProtoBehavior] (which return some stuff data)
2. enable WCF service logging and call method from client proxy
3. see WCF logs

Is it possible to add support a array?

Another issue:
I did not see support inheritance in protobuf for DTO?

for example:
    [DataContract]
    public class DataObjectBase
    {
        [DataMember(Order = 1)]
        public string Name { get; set; }
    }

    [DataContract]
    public class DataObject : DataObjectBase
    {
        [DataMember(Order = 2)]
        public int Number { get; set; }
    }

DataObject.Name always is 'null' at client side. [KnownType] did not help.

OS: Win7 .NET 3.5 sp1
protobuf.net: lastest sources from svn built on Release.

Best Regards,
spassm (spassm{dog}gmail{dot}com)

Original issue reported on code.google.com by spa...@gmail.com on 16 Jun 2012 at 1:09

GoogleCodeExporter commented 9 years ago
I'll investigate the array thing. Inheritance is via ProtoIncludeAttribute, or 
MetaType.AddSubType (to define at runtime)

Original comment by marc.gravell on 16 Jun 2012 at 2:02

GoogleCodeExporter commented 9 years ago
I am also having an issue serializing arrays. The following line of code fails 
if data is string[]

runtimeTypeModel.Serialize(stream, data);

(runtimeTypeModel is of type RuntimeTypeModel)

The exception message is: "Repeated data (a list, collection, etc) has inbuilt 
behaviour and cannot be used as a subclass", 

Stack trace:

protobuf-net.DLL!ProtoBuf.Meta.MetaType.BuildSerializer() Line 350 C#
protobuf-net.DLL!ProtoBuf.Meta.MetaType.Serializer.get() Line 278 + 0x11 bytes 
C#
protobuf-net.DLL!ProtoBuf.Meta.RuntimeTypeModel.Serialize(int key, object 
value, ProtoBuf.ProtoWriter dest) Line 400 + 0x51 bytes C#
protobuf-net.DLL!ProtoBuf.Meta.TypeModel.SerializeCore(ProtoBuf.ProtoWriter 
writer, object value) Line 141 + 0x2e bytes C#
protobuf-net.DLL!ProtoBuf.Meta.TypeModel.Serialize(System.IO.Stream dest, 
object value, ProtoBuf.SerializationContext context) Line 169 C#
protobuf-net.DLL!ProtoBuf.Meta.TypeModel.Serialize(System.IO.Stream dest, 
object value) Line 156 

Original comment by Franches...@gmail.com on 15 Aug 2012 at 12:16

GoogleCodeExporter commented 9 years ago
I am also have an issue when I use protobuf-net as serializer for WCF via 
extension.
Arrays cannot be serialized via protobuf-net.

ProtoOperationBehavior new serializer tries to be created like this:

var model = RuntimeTypeModel.Default;
var serializer = XmlProtoSerializer.TryCreate( model, typeof( Int32[] ) );
Assert.IsNotNull( serializer );

var serializer0 = XmlProtoSerializer.TryCreate( model, typeof( String[] ) );
Assert.IsNotNull( serializer0 );

Both assertion won't pass.

The probem is also with 

var serializerList0 = XmlProtoSerializer.TryCreate( model, typeof( List<String> 
) );
Assert.IsNotNull( serializerList0 );

If introduce some DTO:

    [ProtoContract]
    [DataContract]
    public class Dto
    {
        [DataMember]
        [ProtoMember( 1 )]
        private Int32 id;

        public Int32 Id
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
            }
        }

        public Dto()
        {

        }
    }

will be OK:

var serializerList = XmlProtoSerializer.TryCreate( model, typeof( List<Dto> ) );
Assert.IsNotNull( serializerList );

var serializer1 = XmlProtoSerializer.TryCreate( model, typeof( Dto ) );
Assert.IsNotNull( serializer1 );

Won't be passed:

var serializer2 = XmlProtoSerializer.TryCreate( model, typeof( Dto[] ) );
// Cannot find serializer for array
Assert.IsNotNull( serializer2 );

Original comment by Mikhail....@gmail.com on 15 Jan 2014 at 10:05

GoogleCodeExporter commented 9 years ago
Noticed the same this. The behavior doesn't recognize the array of a registered 
type. Saw this posting that may be of help:
http://stackoverflow.com/questions/22509354/serializing-an-array-in-wcf-with-pro
tobuf-net

Original comment by john.kes...@gmail.com on 18 Apr 2014 at 2:47