WCF/Rest/UriTemplate variable length query string parameter list?
WCF will match this:
http://localhost:8888/test/blahFirst/blahSecond/sdfsdf,wwewe
to this:
[OperationContract]
[WebGet( UriTemplate = "test/{first}/{second}/{val1},{val2}" )]
string GetVal( string first, string second, string val1, string val2 );
Is there a way to make the va11, val2 be a variable length list of parameters? So it could be val1, ...., valN? And end up with a service method such as:
string GetVal( string first, string second, List<string> params );
Or something along thos开发者_JAVA技巧e lines?
Just GET a simple string and then convert it to an Array (or a list) in the method, using the split method.
Your Interface should look something like this:
[OperationContract]
[WebGet(UriTemplate = "test/{first}/{second}/{val1}")]
string GetVal(string first, string second, string val1);
Your implementation:
public string GetVal(string first, string second, string paramArray)
{
string[] parameters = paramArray.Split(',');
foreach (string parameter in parameters)
{
Console.WriteLine(parameter);
}
return "Hello";
}
And call it like this in your browser:
http://localhost:8731/MyServer/test/first/second/1,2,3
Take a look at the MSDN forum for a detailed answer
精彩评论