0

I am using UriTemplate (System.ServiceModel) to bind a template to an object and create a url

var baseUri = new Uri("http://example.com");
var template = new UriTemplate("");

var properties = new NameValueCollection
{
    {"a", "1"},
    {"a", "2"},
    {"a", "3"}
};

Assert.Equal(
    new Uri(baseUri, "?a=1&a=2&a=3"),
    template.BindByName(baseUri, properties));

=>

Expected: http://example.com/?a=1&a=2&a=3

Actual:   http://example.com/?a=1%2c2%2c3

The expected result will work for a webapi endpoint, but the actual does not as the convention of comma separating a parameter is not official and not supported by web api

Is there a way I can get the expected result?

I do need to use url templating for binding values (e.g. {one}/two/{three}), though not necessarily UriTemplate from System.ServiceModel - what does WebApi use? is it exposed?

Anthony Johnston
  • 9,405
  • 4
  • 46
  • 57
  • I don't think that you can achieve this behaviour using the standard .NET classes. Probably, all of them will merge the values into an array. – Sergii Zhevzhyk Dec 23 '15 at 14:00
  • from what I've seen your probably right, seems the servicemodel framework is not compatible with the webapi - but it may be someone has solved this before so will leave this open – Anthony Johnston Dec 23 '15 at 16:09

0 Answers0