0

We're getting ready to create a project where we want to expose data to the public via OData and Soap (to let the users of our API's choose which format they want to consume). I know that the Web API allows you to expose a public action method that has an IQueryable as the return type, and that T value then become queryable from OData. The problem is that our web server sits in a DMZ, and will NOT have direct access to the Entity Framework, thus no direct access to IQueryable. Access to the internal network is done through WCF.

Is there a way to receive the values from an OData call, and proxy those through parameters to the internal network? I've been scouring the internet, and so far, haven't found anything useful. I was thinking I'd just grab the query string directly, pass that through to the internal network, and there, use something like PredicateBuilder to create an EF expression tree, and return the data. That would work, but I'm wondering if there's a better way.

Thanks in advance!

4

2 回答 2

1

自己处理 OData 查询非常容易,您可以返回、IEnumerable或其他任何内容。这是一个例子:IListPageResults

[HttpGet]
[ActionName("Example")]
public IEnumerable<Poco> GetExample(ODataQueryOptions<Poco> queryOptions)
{
    //simulate an EF DbSet for the example
    var data = new Poco[] { 
        new Poco() { id = 1, name = "one", type = "a" },
        new Poco() { id = 2, name = "two", type = "b" },
        new Poco() { id = 3, name = "three", type = "c" }
    };

    var t = new ODataValidationSettings() { MaxTop = 2 };
    queryOptions.Validate(t);

    var s = new ODataQuerySettings() { PageSize = 1 };
    var results = queryOptions
        .ApplyTo(data.AsQueryable(), s) as IEnumerable<Poco>;

    return results;
}

public class Poco
{
    public int id { get; set; }
    public string name { get; set; }
    public string type { get; set; }
}
于 2013-07-30T12:36:33.283 回答
0

我建议使用您的实体框架模型创建一个 WCF 数据服务,并使该服务可用于 DMZ 服务器。几年来,我一直在 DMZ 服务器上运行一个网站,使用这种配置,它运行良好。但是,我承认 WCF 数据服务在如何编写 IQueryable 查询方面确实有一些限制(与直接访问实体框架相比),但似乎随着每个版本的改进而有所改进。

于 2013-08-03T00:09:24.113 回答