如何解决国有无状态的客户端 - 服务器应用程序? [英] How to solve state-stateless in a client-server application?

查看:144
本文介绍了如何解决国有无状态的客户端 - 服务器应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过关于创建无状态的网站一些书,我读过一些关于状态客户端应用程序,但很多复杂的来当你把两者结合起来一起。我们有需要通过.NET服务留存数据到数据库的Flex应用程序。事情要记住的是:
- 并发(乐观/悲观)
- 性能:Flex的需要加载大量的数据,所以延迟加载往往是必要的。
- 您是否使用DTO的转院到服务器和客户端之间的数据

I've read some books on creating stateless websites, I've read some about stateful client applications, but a lot of complexity comes along when you have to combine both. We have a Flex application that needs to persist data to a database via .NET services. Things to keep in mind are: - Concurrency (optimistic/pessimistic) - Performance: Flex needs to load in lots of data so lazy-loading is often necessary. - Do you use Dto's to tranfer data between server and client?

我会告诉你我们的产品的历史。我们从一开始就作为一个O / R映射器使用亚音速。亚音速对象转换为DTO是由我们所撰写这些DTO的被传输到客户端。客户方的转换为域模型的DTO。如果客户方的域模型对象需要保存,它被转换回DTO并传送到服务器。服务器侧的DTO转换为亚音速对象并保存到数据库中。

I'll tell you the history of our product. We've used SubSonic from the beginning as a o/r mapper. SubSonic objects are converted to dto's written by us and these dto's are transferred to the client. Clientside the dto's are converted to the domain model. If clientside a domain model object needs to be saved, it is converted back to a dto and send to the server. Server side the dto is converted to a subsonic object and saved to the database.

现在,前一段时间,我们需要在.NET服务器端的领域模型......所以现在我们有这样三种模式在服务器端,亚音速模式,DTO模式和领域模型。该DTO模式更简单,类似于数据库的更多,领域模型有更多的逻辑。它变得复杂。我们现在必须同步AS3域模型code与C#域模型code。如果我们能再次做到这一点(的时间得到重构)我认为,我们不会使用DTO的了,但客户端和服务器之间传输的域模型。问题是,如果这是现实的。 DTO的是简单对象,所以容易转移。领域模型对象可以是非常复杂的。

Now, some time ago, we needed the domain model on the .NET server side... so now we have like three models on the server side, the subsonic model, the dto model and the domain model. The dto model is more simple and resembles the database more, the domain model has much more logic. It gets complex... We now have to synchronize the AS3 domain model code with the C# domain model code. If we could do it again (of get time to refactor) I think we wouldn't use the dto's anymore, but transfer the domain model between client and server. Question is if this is realistic. Dto's are simple objects so easy to transfer. Domain model objects can be very complex.

是否有关于如何为这些类型的应用程序创建一个架构的书吗?书籍软件写某人有很多的经验吗?你有这方面的经验?

Are there books on how to create an architecture for these kind of applications? Books writte by someone with lots of experience? Do you have experience with this?

推荐答案

现实情况是,客户端和服务器之间共享的对象是相当复杂的。下面是你需要使它发生什么:

The reality is that sharing objects between the client and the server is quite complex. Here's what you need to make it happen:

易于/非可扩展的方式:

继承的所有的从 MarshalByRefObject的的对象。如果在服务器上创建对象A,并将其发送到客户端,任何客户端修改该​​对象将被自动转发到服务器。

Inherit all of your objects from MarshalByrefObject. If you create Object A on the server, and send it to the client, any client modifications to the object will automatically be forwarded to the server.

虽然这听起来像是一个完美的解决方案,它有两个主要问题:

While this sounds like the perfect solution, it has two major problems:


  1. 客户端和服务器的紧密结合.NET(再见Web服务)

  2. 它可以是一个性能噩梦。所有方法/属性的访问将被转发到服务器。如果你选择这条路线,你的对象应该被设计为矮胖通话,不健谈的人。

可扩展/硬方式:

而不是使用 MarshalByRefObject的中,你可以使用 DataContract /序列化的对象。但是:

Instead of using MarshalByRefObject, you would use DataContract/Serializable objects. However:


  • 如果您在服务器上创建的对象A ,并将其发送给客户端,
    客户端将收到的复制的对象(我们称之为对象B

  • 当你发送的对象B 返回到服务器,服务器将收到一个
    复制的对象B的(我们称之为对象C

  • If you create Object A on the server, and send it to the client, the client will receive a copy of the object (let's call it Object B)
  • When you send Object B back to the server, the server will receive a copy of Object B (let's call it Object C)

但你真的希望服务器处理的对象A 对象C 一样。不幸的是,CLR不能做到这一点,所以你需要的对象合并的坐客户端和服务器上。

But you really want the server to treat Object A and Object C as the same. Unfortunately, the CLR cannot do this, so you'll need an Object Merger to sit on both the client and the server.

对象合并的将包含在模型中的所有对象的字典,并且知道如何识别两个实例作为是一样的,并从接收端合并任何值。例如,如果客户机已经在存储器对象C和从服务器接收的更新的副本,这将拷贝过来的值。

The Object Merger would contain a dictionary of all objects within the model, and know how to identify two instances as being the same, and merge any values from the receiving end. For instance, if the client already has Object C in memory, and receives an updated copy from the server, it would copy over the values.

不幸的是,这也是很多问题,因为你需要确保对象引用是preserved正确。不能盲目地在物体上更新所有性质,因为对象可以具有的其他对象,这反过来又可能要求其自己的合并现有的引用。在这一切之上,你还需要跟踪包含在列表或字典添加/删除对象。

Unfortunately, this is also fraught with problems, because you need to ensure that object references are preserved correctly. You can't just blindly update all properties on an object, because the object may have existing references to other objects, which in turn may require their own merging. On top of all this, you would also need to track added/removed objects contained in lists or dictionaries.

我添加n层支持我自己的框架,所以我要通过同样的练习,现在(我走的是可扩展/硬路线)。幸运的是,我有很多的地方进行配套的基础设施,以帮助识别,合并等。如果你是从头开始,这将是一个显著作品。

I adding n-tier support to my own framework, so I'm going through the same exercise right now (I'm taking the "scalable/hard" route). Fortunately, I have a lot of the supporting infrastructure in-place to assist with identification, merging, etc. If you're starting from scratch, it would be a significant piece of work.

P.S。添加延迟加载代理到混合(我使用NHibernate的),它甚至获得的更多的有趣...

P.S. Add lazy-loading proxies into the mix (I'm using Nhibernate), and it gets even more interesting...

这篇关于如何解决国有无状态的客户端 - 服务器应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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