locked
Proxy of mid-tier service. RRS feed

  • Question

  • The project we are working on is a classic 3 tiered architecture. tier 1 being the database server, tier 2 the application services and tier 3 the presentation tier (a web site).

    In the application services tier I have a project that includes an entity framework model and a WCF data services based service that exposes the entities within the model e.g.:

    public class DataService : DataService< PortalEntities >

    This is a fully fledged OData service that can be queried through the URI e.g.: http://localhost:1234/dataservice.svc/mytable?$filter=contains(fieldname,’string’) This is great for the guys developing anything using jQuery as all they have to do is define the query. The problem is that this service is a mid-tier so it cannot be seen by the outside world.

    The solution that I am trying is to expose another WCF data service on the web site that exposes the entities created by the service reference. If I add a service reference to the mid-tier service it gives me a data context that data context is being used in the new WCF Data service: 

    public class DataService : DataService< PortalEntities >

    I do have to overwrite the CreateDataSource:  

    protected override PortalEntities CreateDataSource()

    {

    return new PortalEntities(Sequence.Sambuca.Com.Factory.Current.GetMianModelServiceUri());

    The new service does act like a proxy and does return the entities exposed (the query http://localhost:32130/Services/OData/DataService.svc/tbl_Country works fine).

    But when a query is passed to the service e.g.: http://localhost:32130/Services/OData/DataService.svc/tbl_Country?$select=Name it throws a not implemented exception.

    Any ideas on how to extend the service to suport the queries?

    Thanks,

    Mike

    Wednesday, March 24, 2010 2:41 PM

Answers

  • Hi,

    You're asking for something we internally call "Astoria over Astoria" (Astoria was the code name for WCF Data Services). This doesn't work out of the box, not even close. There are some really hard problems to solve and as of now it doesn't seem to be 100% possible (the WCF Data Services client has different set of abilities than the server and some queries the server uses are not expressible in the OData protocol).

    If you go to http://www.odata.org/developers/odata-sdk there's a link to "OData Provider Toolkit". Aside from the provider samples it also includes a folder called Experimental which contains another one called AstoriaOverAstoria. This is our experiment on trying to implement something like that. It's experimental code, so please refer to it like that. But it should give you the idea of how complicated that can be. Also note that it's read-only for now, if you need your service to allow updates as well, you would need to do more work.

    If you decide to take a look at it, please let us know how it went, we would be very interested in any kind of feedback on this.

    One other suggestion, you might be able to simply "proxy" the requests from the client through the middle tier. Basically just like HTTP proxy, nothing fancy.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by Mike Hole Friday, March 26, 2010 8:52 AM
    Wednesday, March 24, 2010 5:19 PM
    Moderator