This project is read-only.

Supporting arrays of values

Topics: Web Api
Jun 16, 2011 at 4:11 AM

All of the built-in types are readily supported for automatic conversion from the string value returned by the UriTemplateHandler to the operation parameter type (i.e. int, bool, etc.).

However, arrays of those same types are not supported, even though from the URI point of view, they always are. (query strings are parsed to NameValueCollection, which can always have multi-valued keys, and this is indeed what UriTemplate uses internally too).

This makes it quite inconvenient to support simple arrays that would be simple enough to build from the client (i.e. "/products?tag=wpf&tag=wcf").

It would be nice if the built-in behavior was extended to support this scenario without requiring custom operation handlers for each possible type of array.


Jun 16, 2011 at 6:27 AM

Thanks Daniel. I'm going to file a bug to see what we can do here. For now you could create your own dervied handler and replace ours with your own via a custom handler factory.


Jun 16, 2011 at 8:18 AM
yup, done that.

it's in the netfx-WebApi.QueryableService nuget.

it only exposes multi-value query string parameters as string arrays, no other array types supported. It's essentially a minimally tweaked UriTemplateHandler that I hook up with the rest of the queryable support via the HttpQueryableServiceHost.

it's all working smoothly now together with the "linq to web api" in netfx-System.Net.Http.HttpEntityClient :)

Jun 16, 2011 at 8:33 AM

You're an animal :-)