Optional query string parameters in URITemplate in WCF?

Posted by Shafique on Stack Overflow See other posts from Stack Overflow or by Shafique
Published on 2010-06-03T19:47:22Z Indexed on 2010/06/03 19:54 UTC
Read the original article Hit count: 553

Filed under:
|
|
|

I'm developing some RESTful services in WCF 4.0. I've got a method as below:

[OperationContract]
    [WebGet(UriTemplate = "Test?format=XML&records={records}", ResponseFormat=WebMessageFormat.Xml)]
    public string TestXml(string records)
    {
        return "Hello XML";
    }

So if i navigate my browser to http://localhost:8000/Service/Test?format=XML&records=10, then everything works as exepcted.

HOWEVER, i want to be able to navigate to http://localhost:8000/Service/Test?format=XML and leave off the "&records=10" portion of the URL. But now, I get a service error since the URI doesn't match the expected URI template.

So how do I implement defaults for some of my query string parameters? I want to default the "records" to 10 for instance if that part is left off the query string.

© Stack Overflow or respective owner

Related posts about wcf

Related posts about querystring