WCF: How to pass a variable number of parameters to a WebGet enabled service
We're trying to pass a variable number of key-value-pairs to our service by using the WebGetAttribute and 开发者_如何转开发the UriTemplate to expose a REST interface. What we want to do:
[WebGet(UriTemplate="/Query/Select?{query}"]
Response Query(string query);
At client-side we want to specify some keys several times, e.g.:
hllp://localhost/MyService/Query/Select?field=Name&fieldsort=asc&field=IDOur first approach was to use the following UriTemplate and to decompose the key-value-pairs manually:
[WebGet(UriTemplate="/Query/{*query}"]
ResponseQuery(string query);
But this just applies to segments and so URLs like
hllp://localhost/MyService/Query/field=Val%3Due get automatically decoded by WCF and "field=Val=ue" will be passed to the Service method.Even worse, double encoded URLs get fully decoded, too:
hllp://localhost/MyService/Query/field=Val%253Due becomes "field=Val=ue" again.Is there any way, to access the raw query string? If not, can we extend/use UriTemplate in another way, to work with a dynamic number of key-value-pairs?
Using WebOperationContext.Current enabled us to get the raw query string, which will now be parsed by ourself.
精彩评论