none
Pattern for EDM and WCF Services RRS feed

  • Question

  • While utilizing the EDM in WCF Services are there any patterns for defining Service Contracts? If we utilize the Entities generated by the EDM for Service contract, then while consuming the WCF service, entire relevant Entity Model is made available along with the Service Proxy. Which also includes the ObjectContext object where as we want don't want to expose all these entities to the Service Consumer.

    One pattern could be to define a separate XSD based service cotract which is consumed by the Service Consumer. Then it adds additional layer of Entity Translation i.e. from Service Entities to the Entity Model Entities.

    Is there any other pattern that can be applied?

    Wednesday, May 12, 2010 5:04 AM

All replies

  • It's a good question, I'd love to hear what people have done as well.  Just a thought on the subject, this is typically why service contracts are data transfer objects (dtos) and not business entities/objects.
    Wednesday, May 12, 2010 3:55 PM
  • Greetings,

     

    Kindly look into the link which is given below

    WCF Data Services

    http://msdn.microsoft.com/en-us/library/cc668792.aspx

     

    Hope this helps.

     

    Take Care

    PL


    Helping People To Solve Technical Problems
    Wednesday, May 12, 2010 3:58 PM
  •  

    Greetings,

    Also go through the link which is given below

    How to: Create a Data Service Using an ADO.NET Entity Framework Data Source (WCF Data Services)
    http://msdn.microsoft.com/en-us/library/dd728280.aspx

    Defining WCF Data Services

    http://msdn.microsoft.com/en-us/library/ee358708.aspx

    Hope this helps

    Take Care

    PL


    Helping People To Solve Technical Problems
    Wednesday, May 12, 2010 4:00 PM
  • The solution that I have used in the past is to create DTO (data transfer objects) which only contain the 'core' data for the entity and use these in the service contracts.  This requires a translation to/from the business entity / dto and is, in my opinion, far from ideal.  Most of the projects I have worked on where we attemped to use a relation data modeling tool and then expose services through WCF have ended up being modified to remove the modeling tool and create our own data access layer.

    Hope this helps!

    Wednesday, May 12, 2010 5:55 PM
  • If you really want to expose your EDM over with WCF and don't want to write DTOs, try WCF Data Services.  The upside is that it is a lot less code, configuration is a breeze, and it is RESTful.  The downside is that being RESTful, it only runs over HTTP, and does not use SOAP (which could also be a benefit, depending on your viewpoint).
    Don Demsak - MVP Data Platform
    Thursday, May 13, 2010 1:47 PM
  • If you really want to expose your EDM over with WCF and don't want to write DTOs, try WCF Data Services.  The upside is that it is a lot less code, configuration is a breeze, and it is RESTful.  The downside is that being RESTful, it only runs over HTTP, and does not use SOAP (which could also be a benefit, depending on your viewpoint).
    Don Demsak - MVP Data Platform
    Don, forgive my ignorance but how exactly does WCF Data Services solve this problem?  I have never really used this technology but it almost seems to me that it breaks good practices by basically exposing your database (as opposed to services full of logic) to the presentation layer.  For example where before I would call TradingService.GetTrades(userId), now I would write a query against the trades entity directly which will translate into a restful "service" call which will fetch my entity back to the UI.  Perhaps I am missing the point but I always viewed WCF Data Services as something to expose public information/lookup data rather than for business type work.
    Thursday, May 13, 2010 3:50 PM