在 WCF 客户端和服务之间共享合约
我的理解是,当开发人员(公司)同时开发客户端和服务时,最好将数据和服务契约放入单独的程序集中,以供客户端和服务应用程序使用。这是为了避免在使用 svcutil 等生成代理类时出现代码重复。
这确实是首选方法吗?您是否曾经有过一个不符合此规则的项目?
It was my understanding that when a developer (a company) develops both client and service, it’s better to put data and service contracts into a separate assembly to be used by both client and service applications. It is to avoid code duplication while generating a proxy classes using e.g. svcutil.
Is this indeed the preferred approach and have you ever had a project that was an exception from this rule?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们在项目中一直这样做,我不知道有什么可以反对这种方法。
We do this all the time in our projects and i don't know what can be said against that approach.
共享合约程序集可能会导致不必要的依赖关系,因为这些合约类(例如 datacontract\servicecontract)可以包含方法。然后,这些方法可以在客户端\服务器代码中透明地调用,从而打破了这些契约的封装。数据\服务合约仅用作共享数据的机制。
Sharing contract assembly can lead to unwanted dependencies, since these contract classes such as datacontract\servicecontract can contain methods. These methods then can get called transparently in client\server code hence breaking the encapsulation of these contracts. Data\Service contracts are meant to be used only as an mechanism to share data.