List of query string parameters for string length WCF / Rest / UriTemplate?

WCF will match this:

http: // localhost: 8888 / test / blahFirst / blahSecond / sdfsdf, wwewe

:

[OperationContract]
[WebGet( UriTemplate = "test/{first}/{second}/{val1},{val2}" )]
string GetVal( string first, string second, string val1, string val2 );

Is there a way to make va11, val2 a variable parameter list? So it could be val1, ...., valN? And ultimately using a service method, for example:

string GetVal( string first, string second, List<string> params );

Or something like that?

+5
source share
1 answer

Just create a simple string and then convert it to an array (or list) in a 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 name it in the browser as follows:

http://localhost:8731/MyServer/test/first/second/1,2,3

Take a look at the MSDN forum for a detailed answer

+6

All Articles