系统从另一个系统,当底层数据库有关系,消费WCF服务 [英] System consuming WCF services from another system, when underlying databases have relationships

查看:145
本文介绍了系统从另一个系统,当底层数据库有关系,消费WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在许多系统挣扎着一个问题,但这个人是一个很好的例子。这是当一个系统从另一个系统消耗WCF服务,做的,每个系统都有自己的数据库,但有两个数据库之间的关系。

This is an issue that I have struggled with in a number of systems but this one is a good example. It is to do with when one system consumes WCF services from another system, and each system has their own database, but there are relationships between the two databases.

我们有一个持有该公司的所有文件的记录的中央数据库。这个数据库包括文件和文件夹表和它mimicks Windows文件结构。 NHibernate的需要照顾的数据访问,领域层处理逻辑(验证文件名/在同一文件夹等不相同的文件名)和服务层位于上,名为服务CreateDocument(字节[])','RenameDocument(ID ,了newName),SearchDocuments(文件名,文件大小,createdDate)等暴露与WCF这些服务。

We have a central database that holds a record of all documents in the company. This database includes Document and Folder tables and it mimicks a windows file structure. NHibernate takes care of data access, a domain layer handles logic (validating filenames/no identical filenames in the same folder etc.) and a service layer sits on that, with services named 'CreateDocument(bytes[])', 'RenameDocument(id, newName) ', 'SearchDocuments(filename, filesize, createdDate)' etc. These services are exposed with WCF.

这是HR系统消耗这些服务。人力资源数据库有有外键的文档数据库单独的数据库:它包含有一个外键DocumentId的HRDocument表,然后HR相关的,例如雇员和ContractId

An HR system consumes these services. The HR database has a separate database that has foreign keys to the Document database: it contains an HRDocument table that has a foreign key DocumentId, and then HR specific such as EmployeeId and ContractId.

下面是问题amonst他人:

Here are the problems amonst others:

1)为了保存文档时,我必须调用WCF服务将其保存到中央数据库,返回ID,然后保存到HRDocument表(与HR的具体信息一起)。因为WCF调用和所有文档具体的数据访问被文档应用程序中完成的,这个不能做都是一个事务中,造成诚信交易的可能损失。

1) In order to save a document, I have to call the WCF service to save it to the central db, return the ID and then save to the HRDocument table (along with the HR specific information). Because of the WCF call and all Document specific data access being done within the Document application, this can't be done all within one transaction, resulting in a possible loss of transaction integrity.

2)为了上说,雇员和createdDate搜索,我要调用搜索服务传入createdDate(文档数据库中的特定字段),然后搜索上的ID的返回的记录来筛选结果HRDocument数据库回。这种感觉凌乱,速度慢,错误的。

2) In order to search on say, employeeId and createdDate, I have to call the search service passing in the createdDate (Document database specific fields) and then search the HRDocument database on the Id's of the returned records to filter the results returned. This feels messy, slow and just wrong.

我可以在人力资源应用程序的DAL复制NHibernate的映射文件的文档数据库。这意味着我可以指定HRDocument和文档之间的关系。这意味着我可以加入的表和搜索这样的,但也意味着我会重复域逻辑并违反了DRY原则,所有这就需要。

I could duplicate the NHibernate mapping files to the Document database in the DAL of the HR application. This means I could specify the relationship between HRDocument and Document. This means I could join the tables and search like that but would also mean I would have to duplicate domain logic and violate the DRY principle, and all that entails.

我不禁感慨,我在这里做得不对,并错过了简单的东西。

I can't help feeling I'm doing something wrong here and have missed something simple.

推荐答案

我建议你申请 CQRS 并事件驱动架构原则在这里

I recommend you to apply CQRS and Event Driven Architecture principles here



    • 使用的GUID作为主键 - 那么你
      将能产生主键
      文档并将它传递给WCF结果
      方法调用。

    • 在WCF服务的另一边prevent数据丢失使用短信
      (在数据库故障和结果的情况下,
      类似的东西)。

    • 数据库之间删除constaints - 立即
      一致
      应用不
      规模。使用最终一致性
      范式来代替。

介绍了单独的数据存储
    读取包含非标准化数据的目的。然后,你就可以
    做搜索非常容易。确保
    在你读存储(一致性
    情况下,当文件创建
    失败的),你可以实现一些
    简单的工作流(<一href=\"http://abdullin.com/journal/2010/9/26/theory-of-cqrs-command-handlers-sagas-ars-and-event-subscrip.html\"相对=nofollow>而言传奇
    CQRS)

Introduce separate data storage for reads purpose that contains denormalized data. Then you will be able to do search very easy. To ensure consistency in your read storage (in case when Document creation failed) you could implement some simple workflow (saga in terms of CQRS)

这篇关于系统从另一个系统,当底层数据库有关系,消费WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆