OData and custom WCF WebGet methods
문제
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.
해결책
The right way is: /myservice.svc/SplitString?testtext='mystringvalue'
See this page for more details: http://msdn.microsoft.com/en-us/library/cc668788.aspx
제휴하지 않습니다 StackOverflow