0
votes

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!

2

2 Answers

1
votes

It's very easy to handle the OData queries yourself and you can return IEnumerable, IList, PageResults or whatever. Here's an example:

[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; }
}
0
votes

I’d suggest creating a WCF Data Service using your Entity Framework model and make that service available to the DMZ server. I’ve been running a web site, on a DMZ server, with this configuration for a few years now and it has worked well. However, I will admit that WCF Data Services does have some limitations (compared to direct access to Entity Framework) on how you can compose your IQueryable queries but seems to improve with each release.