使用数组作为参数的ServiceStack路由

时间:2016-12-01 02:54:32

标签: c# servicestack ormlite-servicestack

我需要使用URL为请求创建此ServiceStack,但我无法找到将其生成为URL路由的方法:

http://server.com/myserver?service=2&item[0].reference=222&item[1].reference=233

下面你可以看到我的尝试:

[Route("myserver", "GET")]
public class Request1: IReturn<string>
{
   public int Service { get; set; }
   public List<Item> item { get; set;}
}

public class Item
{
  public int Reference { get; set; }
}

1 个答案:

答案 0 :(得分:2)

首先,你应该避免在这样的queryString上设计接受复杂类型的API,因为它会降低互操作性,因为每个支持发送复杂类型的框架都会有不同的做法。

但是不清楚为什么要为ServiceStack请求创建这样的url,因为ServiceStack期望已经内置到C#服务客户端的complex types using the JSV Format

我假设您没有尝试将此请求发送到ServiceStack服务,而是希望将其发送到第三方API。 ServiceStack的C# Service Clients主张与ServiceStack Services进行通信,如果您想向第三方API发送请求,我建议您使用HTTP Utils,您可以自由创建请求。

但一般来说,如果你想自定义queryString的生成方式,你可以use a custom IUrlFilter