OData and custom WCF WebGet methods

Toad picture Toad · May 31, 2010 · Viewed 11.7k times · Source

I've created an OData endpoint (using entity framework, WCF data service)

and added a custom test WebGet test method like so:

    [WebGet(UriTemplate = "{text}")]
    public IQueryable<string> SplitString(string text)
    {
        if (text == null) throw new DataServiceException("text not specified");
        var result = (from s in text.Split('-') orderby s select s);
        return result.AsQueryable();
    }

and a config line:

    config.SetServiceOperationAccessRule("SplitString", ServiceOperationRights.All);

However, no matter how I specify the url, I can not get the text param to be filled out. (it is always null).

so:
http://localhost/myservice.svc/SplitString/testtext

does not work (It throws my Exception since the param is null). What is the correct url format (or UriTemplate) one should use to get the parameter to work?

The only examples I found of odata and WebGet only have an example method which doesn't have any parameters.

Answer

Vitek Karas MSFT picture Vitek Karas MSFT · Jun 11, 2010

The right way is: /myservice.svc/SplitString?testtext='mystringvalue'

See this page for more details: http://msdn.microsoft.com/en-us/library/cc668788.aspx