OData 和自定义 WCF WebGet 方法

发布于 2024-09-03 09:35:04 字数 855 浏览 3 评论 0原文

我创建了一个 OData 端点(使用实体框架、WCF 数据服务)

并添加了一个自定义测试 WebGet 测试方法,如下所示:

    [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();
    }

和一个配置行:

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

但是,无论我如何指定 url,我都无法获取文本参数被填写。 (它始终为空)。

所以:
http://localhost/myservice.svc/SplitString/testtext

不起作用(它抛出我的异常,因为参数为空)。 应该使用什么正确的 url 格式(或 UriTemplate)才能使参数正常工作?

我发现的 odata 和 WebGet 的唯一示例只有一个没有任何参数的示例方法。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦冥 2024-09-10 09:35:04

正确的方法是:
/myservice.svc/SplitString?testtext='mystringvalue'

请参阅此页面了解更多详细信息:
http://msdn.microsoft.com/en-us/library/cc668788.aspx

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文