ServiceStack空元数据

时间:2013-01-27 22:17:50

标签: servicestack

看到一个奇怪的问题,获取xml,json和jvs的空元数据页面。 使用以下命令行应用程序。如何调试这些问题?

namespace ConsoleApplication2
{
    public struct NativeUser
    {
        public int login;
        public string group;
        public string name;
    }


    [DataContract]
    public class User
    {
        private NativeUser _native;

        public User() { }


        public User(NativeUser native)
        {
            _native = native;
        }

        public static implicit operator NativeUser(User user)
        {
            return user._native;
        }

        public static implicit operator User(NativeUser native)
        {
            return new User(native);
        }

        // ReSharper disable InconsistentNaming
        [DataMember]
        public int login
        {
            get { return _native.login; }
            set { _native.login = value; }
        }

        [DataMember]
        public string group
        {
            get { return _native.group; }
            set { _native.group = value; }
        }
        [DataMember]
        public string name
        {
            get { return _native.name; }
            set { _native.name = value; }
        }
    }


    [Description("GET account, all or by list of groups or by list of logins")]
    [Route("/accounts/{groups}", "GET")]
    [Route("/accounts/{logins}", "GET")]
    [Route("/accounts/", "GET")]
    public class Accounts : IReturn<User[]>
    {
        public string[] groups { set; get; }
        public int[] logins { set; get; }

        public Accounts() { }

        public Accounts(params int[] logins)
        {
            this.logins = logins;
        }

        public Accounts(params string[] groups)
        {
            this.groups = groups;
        }
    }

    public class Host : AppHostHttpListenerBase
    {
        public Host() : base("Test", 
                            typeof(Accounts).Assembly)
        {

        }

        public override void Configure(Funq.Container container)
        {

        }
    }

    public class Servce : IService
    {
        public object Get(Accounts request)
        {
            return new List<User>(){new User(new NativeUser())};
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            var host = new Host();
            host.Init();
            host.Start("http://+:12345/");

            global::System.Console.ReadLine();

        }
    }
}

1 个答案:

答案 0 :(得分:1)

Nm,找到了错误:

public class Accounts : IReturn<User[]>

需要

public class Accounts : IReturn<List<User>>

另一个非常值得注意的事情:在DTO中传回和传递的所有DTO和对象都需要一个空构造函数,以便正确生成元数据。 不确定这是设计还是错误