WCF Data Service - Proxy mid-tier service

后端 未结 2 1810
Happy的楠姐
Happy的楠姐 2021-01-25 10:59

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)

2条回答
  •  爱一瞬间的悲伤
    2021-01-25 11:47

    I have found it possible to expose a service on the Web Tier that references a service (not data directly) on the App Tier. This only works for queries at the moment. I am not sure what is needed to get it working for updates, deletes etc. Any Ideas anyone? Anyway, here are some instructions and code snippets:

    1. First you create a WCF Data Service on the App Tier bound to your edmx model.
    2. Then create WCF Data Service on the Web Tier not bound to an edmx model (custom).
    3. Create a Service Reference in the Web Tier Service to the App tier service.
    4. Pass the Entities type to the DataService generic declaration (should be angle brackets for VB but I couldn't get them to show:
    
            Public MyWebTierService 
            Inherits DataService[MyServiceReference.MyAppTierEntities]
    
    1. Add an override for CreateDataSource() that creates your reference to the App Tier:
    
     Protected Overrides Function CreateDataSource() As MyServiceReference.MyAppTierEntities
            Dim ctx = New MyServiceReference.MyAppTierEntities(New Uri("http://yourappservicelocation/AppService.svc/"))
            Return ctx
        End Function
    

    All you do now is create a reference to the service or bind it to your client app that supports OData. JSONP support can be added if required.

    So, this works fine for Queries but not for updates, probably because the Types are not the same (they may look the same, but are in difference assemblies after all). So, tracking is lost between the Web and App Tiers.

    It may be that we have to implement IUpdatable on the Web Tier to solve this. Not sure yet so any input would be useful.

    Hope this helps

提交回复
热议问题