缺少ServiceStack请求参数

时间:2016-04-22 19:38:48

标签: c# .net servicestack

我正在使用ServiceStack进行服务,我遇到了问题。我没有看到请求参数,因此,当我调用该方法时,请求的所有参数都为null。 这是代码:

public class AppHost : AppSelfHostBase
{
    public AppHost()
        : base("CallbackServer", typeof(CallbackServer).Assembly)
    {
    }

    public override void Configure(Container container)
    {
    }
}

public class CallbackServer : Service
{
    public HttpResult Post(EventoCliente request)
    {
        request.TimeReceived = DateTime.Now;
        Task.Factory.StartNew(() => Program.EventArrived(request));
        return new HttpResult(HttpStatusCode.OK,"OK");
    }
}

[Route("/turno", "Post")]
public class EventoCliente : IReturn<EventoClienteResponse>
{
    public TurnoCliente Turno;
    public string Sucursal;
    public string[] Puestos;
    public DateTime? TimeReceived;
}

public class EventoClienteResponse
{
    public ResponseStatus ResponseStatus { get; set; }
}

static void Main()
{
    var appHost = new AppHost();
    appHost.Init();
    appHost.Start("http://*:9900/NesrEmulator/");
}

所以,在我写的浏览器中:http://localhost:9900/NesrEmulator,我可以看到方法EventoCliente,但我看不到(没有)请求的参数。 Here is a screenshot of what i mean...

我做错了什么? 感谢

1 个答案:

答案 0 :(得分:2)

您的DTO应使用公共属性而非公开字段,因此只需将其更改为:

[Route("/turno", "Post")]
public class EventoCliente : IReturn<EventoClienteResponse>
{
    public TurnoCliente Turno { get; set; }
    public string Sucursal { get; set; }
    public string[] Puestos { get; set; }
    public DateTime? TimeReceived { get; set; }
}