0
votes

In a project I'm working on, there's a need for following architecture (simplified):

[WebAPI] -> [WCF -> Entity Framework] -> [Database]

I've seen a lot of demo's where you can expose your Entity Model directly over a WebAPI with OData syntax.

I was wondering though, whether it is possible to expose a WCF OData Service (backend server) over a WebAPI OData service (frontend server) with the benefits you get with OData filtering.

For example: I don't want to get all Customers from WCF when I filter on country in my WebAPI (http://domain.com/api/Customers?$filter=country eq 'USA').

Thanks!

1

1 Answers

0
votes
  1. If you mean WCF Data Services, it is already an OData service endpoint that supports filter.

    e.g.:

    http://services.odata.org/OData/OData.svc/Categories?$filter=Name eq 'Food'

  2. If you mean WCF service backended by EF, then you're to make the WebAPI OData service a proxy to the WCF service. That is viable as long as you could write client code to consume the WCF service.

    Please refer to: http://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/ODataServiceSample/ODataService/

    You can simply replace the code snippet inside ProductsController::Get, retrieve data from the WCF service, then return the data there. The [EnableQuery] attribute would make the query options available.