Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 those lines?

like image 735
MonkeyWrench Avatar asked Sep 30 '10 16:09

MonkeyWrench


1 Answers

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

like image 94
Jeff Caron Avatar answered Nov 15 '22 08:11

Jeff Caron