使用Protobuf-net和Monotouch for IOS序列化IEnumerable槽WCF

Jea*_*erc 6 c# ienumerable wcf serializer protobuf-net

我正在尝试在Monotouch/Monodevelop上为IOS编写WCF服务.我使用[DataMember]/[DataContract]等标准属性作为我的可序列化对象,使用[ServiceContract]/[OperationContract]作为我的界面.一切正常,但是当我尝试在接口实现(服务器端)上实现返回IEnumerable的方法时,它没有用.

所以为了解决我的问题,我尝试使用最新版本的protobuf-net protobuf-net v2 beta r404.但我仍然从Protobuf-net收到序列化错误.请注意,"MyObject"中的IEnumerable序列化没有问题.

以下是我的代码现在的样子:

为MyObject:

[ProtoContract]
public class MyObject
{
    public MyObject ()
    {
    }

    [ProtoMember(1)]
    public int Id {get;set;}

    [ProtoMember(2)]
    public IEnumerable<MyObject> myObjects {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

我的界面(Windows上的服务器端):

[ServiceContract]
public interface ITouchService
{
        [OperationContract, ProtoBehavior]
        MyObject Execute();

    [OperationContract, ProtoBehavior]
    IEnumerable<MyObject> ExecuteENUM ();
}
Run Code Online (Sandbox Code Playgroud)

我的界面(IOS上的客户端,我无法添加ProtoBehavior作为属性,因为它不在protobuf的ISO dll中):

[ServiceContract]
public interface ITouchService
{
    [OperationContract]
    MyObject Execute();

    [OperationContract]
    IEnumerable<MyObject> ExecuteENUM ();
}
Run Code Online (Sandbox Code Playgroud)

我的界面实现:

public class TouchService : ITouchService
    {
        public MyObject Execute()
        {
            var myObject = new MyObject() { Id = 9001 };

            var myList = new List<MyObject>();

            for (int i = 0; i < 10; i++)
            {
                myList.Add(new MyObject() { Id = i });
            }

// Will serialize
            myObject.myObjects = myList;

            return myObject;

        }

        public IEnumerable<MyObject> ExecuteENUM()
        {
            var myEnum = new List<MyObject>();

            for (int i = 0; i < 10; i++)
            {
                myEnum.Add(new MyObject() { Id = i });
            }

            return myEnum;
        }
    }
Run Code Online (Sandbox Code Playgroud)

Mar*_*ell 2

我怀疑应该可以为此调整数据契约序列化器代码。我会看一看。

现在:我的建议是返回一个具有IEnumerable<T>作为属性的明显的具体类型。或者也许返回 a List<T>,这可能会起作用。

不过,支持这种情况听起来很合理。我会看看我能做什么。