5

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?

MonkeyWrench
  • 1,759
  • 2
  • 21
  • 47

1 Answers1

6

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

Jeff Caron
  • 403
  • 6
  • 14
  • Basically I've found the answer to my question is "No, you can't do that directly." But yes, your method will work. I'll give it a check anyways. – MonkeyWrench Jan 14 '11 at 16:43