tags:

views:

475

answers:

1

I'm working with a rather large query string(~30+ parameters) and am trying to pass them to a WCF service I've setup.

I've run into a few issues specifically with the UriTemplate field. This service is setup to access a third party Api, so the query string may or may not contain all parameters. I'm curious if the best approach is to build a query string and pass that to the WCF service or to pass each parameter(and in some cases String.Empty) individually.

I've currently tried to dynamically build up a query string, however have hit a wall with either a 403 error when I try to pass the entire string( "?prm1=val&prm2=val" ) into the uritemplate of "ApiTool.jsp{query}", or I hit an invalid uritemplate response due to the fact I don't have name/value pairs listed.

A: 

I am pretty sure you'll need to list the parameters individually. Otherwise, UriTemplate will end up escaping things for you:

    var ut = new UriTemplate("Api.jsp{query}");
    var u = ut.BindByName(new Uri("http://localhost"), new Dictionary<string, string>() { { "query", "?param1=a&param2=b" } });
    Console.WriteLine(u); // http://localhost/Api.jsp%3Fparam1=a&amp;param2=b
JLamb
After getting deeper into this, I have to agree. It's a little cumbersome when dealing with a dynamic amount of paramaters(ie, param1, param2...paramN), but I haven't been able to see a way around it.
Alexis Abril