I am trying to create my WebAPI controller with overloaded Get methods that will be selected based on parameters provided by the user. I can make this work properly in some cases, but when I have several collection parameters for a method, my controller can no longer select the correct route, even if I do not specify both collections.
For example, the following settings work:
[RoutePrefix("data/stock")]
public class StockDataController
: ApiController {
private readonly IDataProvider<StockDataItem> _dataProvider;
public StockDataController() {
_dataProvider = new StockDataProvider();
}
[Route("")]
public IEnumerable<StockDataItem> Get([FromUri] string[] symbols) {
}
[Route("")]
public IEnumerable<StockDataItem> Get([FromUri] string[] symbols, DateTime time) {
}
}
Selects method 1
GET http: // server / data / stock /? Symbols [] = GOOG & symbols [] = MSFT
Selects Method 2
GET http: // server / data / stock /? Symbols [] = GOOG & symbols [] = MSFT & time = 2015-01-01
As soon as I add the following overload then everything will break:
[Route("")]
public IEnumerable<dynamic> Get(
[FromUri] string[] symbols, [FromUri] string[] fields) {
}
, 3:
GET http://server/data/stock/?symbols[]=GOOG&symbols[]=MSFT&fields[]=Price&fields[]=Volume
:
, : Get on type StockDataController Get on type StockDataController
? , ?