层/层如何在n层体系结构中的机器/层之间相互通信 [英] How layer/tier communicate each other between machine/tier in n tier architecture

查看:126
本文介绍了层/层如何在n层体系结构中的机器/层之间相互通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目(桌面应用程序)中,我将业务逻辑和表示层分开,但在同一台机器上运行。所以这里是组成:

A.表示层和业务层在客户端(用户)运行。

它由2个项目/程序集组成:UI(演示文稿)和类库(bussines层)。至少这是我对分层应用程序的了解。

B.数据层(数据库服务器)。



看了很多关于3层和n层架构的文章,他们说每层意味着一台机器或在一台计算机上运行。我想知道每层如何沟通?

例如,我想将数据从数据访问层绑定到UI。如果它们在不同的机器上运行,我们怎么能这样做?

在我当前的项目中,我只需添加充当数据访问层的类库作为项目参考。



Web服务是(唯一的)答案可以实现吗?如果答案是肯定的,那么SOA和N层是如何相关的吗?



我尝试了什么:



阅读大量文章并尝试实施SOA

In my project(desktop application), I separate business logic and presentation layer but run in the same machine. So here are the composition:
A. Presentation layer and business layer run on the client side(user).
It is consist of 2 project/assembly: the UI(presentation) and class library(bussines layer). At least this is what I know about layering an application.
B. Data layer(the database server).

After reading a lot of articles about 3 and n tier architecture, and they said each tier mean one machine or run in one computer. I wonder how each tier communicate?
For example i want to bind data from data access layer to the UI. How can we do this if they run on different machine?
In my current project i just simply add the class library who act as the data access layer as project reference.

Is web service is the (only) answer to make it possible? And if the answer is yes, is this how SOA and N tier is related?

What I have tried:

Reading a lot of article and tried to implementing SOA

推荐答案

不要挂断术语或人们称之为什么层或层。所有重要的是适合您的解决方案。如果您需要扩展解决方案,或者在某些防火墙后面提供某些服务等,通常会将代码拆分到物理机上。



在沟通方面,很多应用程序将他们的解决方案分解为所有在同一台机器上运行的代码,甚至是同一个进程,并且通过标准的DLL内部通信来处理通信...即,您的业务层将数据层程序集加载到其空间中并调用其对象上的方法。



如果你想要选择在服务器或进程之间拆分代码那么那就不行了,所以你需要使用WCF之类的代码。请注意,WCF不是Web服务。当涉及客户端和服务器之间的通信时,http通信只是对WCF开放的一个选项。将WCF通信视为黑盒子......您的代码会创建一个客户端对象并在该客户端上调用方法。最终,在服务器上执行相同的方法以及中间位的工作方式是不相关的... WCF只是为您处理它,它是由配置组成的。因此,您可以将此配置为使用http,因为您的业务层在外部托管,稍后您决定要获得更好的性能,因此请将您的应用层带入本地网络,并希望使用TCP而不是HTTP。要做到这一点,只需要重新配置WCF以使用TCP而不是HTTP,您不必更改代码,您的代码不知道,也不关心WCF如何传输您的请求。如果你愿意,你仍然可以在同一台机器上托管所有层,然后在以后拆分到不同的机器,这只是你如何配置WCF,不需要更改代码。
Don't get hung up on terminology or what people call tiers or layers. All that is important is what is right for your solution. Splitting your code onto physical machines is usually done if you need to scale the solution, or have certain services behind certain firewalls etc.

In terms of communicating, a lot of apps split their solutions into code that all runs on the same machine, even same process, and communication is handled by standard intra-DLL communication...ie your business layer loads the data layer assembly into its space and calls methods on its objects.

If you want the option to split the code across servers or processes then that's not going to work so you'll need to use the likes of WCF. Note that WCF isn't "web services" though. http communication is simply one option open to WCF when it comes to communication between client and server. Think of WCF communication as being a black box...your code creates a client object and calls a method on that client. Ultimately the same method is executed on the server and how the bit in the middle works isn't relevant...WCF just handles it for you and it is down to configuration. So you might configure this to use http as your business layer is hosted externally somewhere, and later on you decide you want better performance so bring your app layer into your local network and want to use TCP rather than HTTP. To do this simply means re-configuring WCF to use TCP rather than HTTP, you don't have to change your code, your code doesn't know and doesn't care how WCF is transmitting your requests. Also you can still host all tiers on the same machine if you want to, then split to different machines later and again it's simply down to how you configure WCF, no code changes needed.


这篇关于层/层如何在n层体系结构中的机器/层之间相互通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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