首页 > 解决方案 > 包含列表的 HttpChannel MarshalByRefObject

问题描述

我想实现这一点,我复制粘贴并创建了一个包含RemoteObject

远程对象如下所示:

    public class RemoteObject : MarshalByRefObject
    {
        readonly List<String> strings=new List<String>();

        public void Add(string value)
        {
            strings.Add(value);
        }

        public List<String> Get()
        {
            return strings;
        }
    }

但是当我尝试从客户端添加元素时:new RemoteObject().Add("aaa");我收到以下异常:

System.Runtime.Serialization.SerializationException:“Soap 序列化程序不支持序列化通用类型:System.Collections.Generic.List`1[System.String]。”

使用链接中的示例,它可以正常工作:

public class RemoteObject : MarshalByRefObject
{
    private int callCount = 0;

    public int GetCount()
    {
        Console.WriteLine("GetCount was called.");
        callCount++;
        return(callCount);
    }

}

我的问题是如何制作可以包含某种列表的 RemoteObject。

相关,但不起作用

标签: c#

解决方案


推荐阅读