简体   繁体   English

用于业务和数据层的 WCF 主机

[英]WCF host for business and data layer

I checked alot of multi tier application guides and none talked about how to use wcf to host the layers.Im planning to make a test project and ill have a presentation layer/business layer/data layer along with the business objects which are classes generated automatically by EF (database first).我检查了很多多层应用程序指南,但没有人谈到如何使用 wcf 来托管层。我打算制作一个测试项目,并且有一个表示层/业务层/数据层以及自动生成的类的业务对象通过 EF(数据库优先)。

Question is, in real world, would the business layer and data layer each be accessed by way of a wcf host aka 2 hosts?问题是,在现实世界中,业务层和数据层是否都可以通过 wcf 主机(即 2 台主机)访问? or only 1 host?还是只有 1 个主机?

1 between data and business layer 1 between business and presenation layer 1 数据层和业务层之间 1 业务层和展示层之间

Just for clarity,只是为了清楚起见,

A Layer could be just another project but on the same box.一个层可能只是另一个项目,但在同一个盒子上。

A Tier is the physical separation of the code on separate servers.层是不同服务器上代码的物理分离。

Whether you are using layers or tiers or a mix of them depends on the needs.您是使用层还是层,还是混合使用它们取决于需求。 When I was working at a medical based company that also handled payment information they were shooting for a high level of PCI compliance so we had various tiers.当我在一家也处理支付信息的医疗公司工作时,他们正在追求高水平的 PCI 合规性,因此我们有不同的层级。

My [brackets] are physical barriers such as servers and routers.我的[括号]是物理屏障,例如服务器和路由器。

[Front end -> MVC] -> [Firewall] -> [WCF -> Business layer servers] -> [Firewall] -> [WCF -> Database access] -> [Databases]

They also had another set of tiers to handle the PCI data specifically that branched from the business tier.他们还有另一组层来处理专门从业务层分支出来的 PCI 数据。

Would this be ideal for your situation?这是否适合您的情况? It really depends on the requirements of the project.这实际上取决于项目的要求。 If your data doesn't need to be highly secure then you could stick with just using layers instead.如果您的数据不需要高度安全,那么您可以坚持只使用层。 If you plan on having a few front-end components like mobile platforms and websites then you could shoot for..如果您计划拥有一些前端组件,例如移动平台和网站,那么您可以争取……

[Front end -> MVC] -> [WCF/WebAPI -> Business Layer -> Data access Layer] -> [Database]

That would allow you to have multiple front ends to work with while sharing a common business layer and data.这将允许您在共享公共业务层和数据的同时使用多个前端。 Again it is all depending on what your needs are.同样,这完全取决于您的需求。 I hope this helped.我希望这有帮助。

EDIT: Security is not the only reason for having tiers, accessibility and performance is another.编辑:安全性不是拥有层级的唯一原因,可访问性和性能是另一个原因。 If you are a heavy hitting application having multiple tiers with server farms utilizing them would allow for a few advantages.如果您是一个具有多个层次的重磅应用程序,并且服务器群使用它们,那么您将获得一些优势。 If your business layer is in a server farm of 30 servers you would have wide bandwidth and more processing power.如果您的业务层位于 30 台服务器的服务器群中,您将拥有宽带宽和更强的处理能力。 These tiers could be distributed across the country or the world and have rules setup so users access the closest servers to them.这些层可以分布在全国或世界各地,并设置规则,以便用户访问离他们最近的服务器。 There are a bunch of considerations when developing for tiers, starting out with layers will allow you to physically separate them into tiers at a later time if the demand comes for it.在为层进行开发时有很多考虑因素,如果需要,从层开始将允许您在以后将它们物理地分成层。 If you design the code well the move would be adding the additional service layer WCF/WebAPI to the tier to allow it to access the separated layer and then updating the calling end to use the service instead of the assembly directly.如果您将代码设计得很好,那么此举将是向层添加额外的服务层 WCF/WebAPI,以允许它访问分离的层,然后更新调用端以使用服务而不是直接使用程序集。

Typically, you only host the business logic.通常,您只托管业务逻辑。 If you host both the business and the data access layer, you'd have 3 network hops on each action: Presentation to Business to Data Access to Database.如果您同时托管业务层和数据访问层,则每个操作都有 3 个网络跃点:向业务展示到数据访问到数据库。 Each transfer over the network takes some time, so the less hops you have the better your application performs.通过网络进行的每次传输都需要一些时间,因此您的跳数越少,应用程序的性能就越好。

From an architectural point of view, the most important thing is to split the functionality of the application in layers that each serve a specific purpose (separation of concerns).从架构的角度来看,最重要的是将应用程序的功能划分为多个层,每个层都服务于特定目的(关注点分离)。 However, the infrastructure view is a different one, so this does not mean that each layer does have to be hosted on a server.然而,基础设施视图是不同的,所以这并不意味着每一层都必须托管在服务器上。 If you have a small intranet application, it might be enough to just split the application in layers and run all of them in the UI process.如果您有一个小型 Intranet 应用程序,可能只需将应用程序拆分为多个层并在 UI 进程中运行所有这些应用程序就足够了。 If the requirements change, you can layout the layers in a different way later easily.如果需求发生变化,您可以稍后轻松地以不同的方式布置图层。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM