开发者

Multiple SVC references each exposing same entities

I have a WPF application that uses a WCF services to perform operations on entities using EF4. My project structure is as follows:

Project: EntityObjects

  • this is where the edmx file lives

Project: WCFService

  • References EntityObjects
  • Has data contracts to perform actions on entities
  • Has three different svc files, called Part开发者_高级运维ner.svc, Section.svc, Scheme.svc

Project: DataLayer

  • has service references to Partner.svc, section.svc, scheme.svc

The problem is that the DataLayer project then has ambiguous references to objects as each svc file returns its own references of the entity objects.

How do I get around this?


It will not work this way. If you want to have same data contract types among all three service references you must use data contract sharing. That means that your data contracts must be provided to client project in separate assembly prior to adding service references. Most often this means that you will share data contract assembly between server and client. In your case it means sharing EntityObjects with whole EF stuff - that is bad.

There are multiple solutions:

  • Placing entities and EDMX stuff into separate projects and share only project with entities
  • Use custom Data transfer objects instead of entities as data contracts and share assembly with these DTO
  • Don't share assembly and instead create "copy" of data contracts manually for client
  • Don't expose same entities through different services
  • Use only single service if it makes sense in your architecture

Last two choices are more about architecture of your application.


You could :

Build a wrapper class that wrapped access to all 3 services. Then reference the objects concerned in the DataLayer project directly rather than through the service and convert as required in the wrapper class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜