有状态与无状态 Web 服务

发布于 2024-08-27 21:25:24 字数 690 浏览 7 评论 0原文

想象一个更复杂的 CRUD 应用程序,它具有三层架构并通过 Web 服务进行通信。客户端开始与服务器进行对话并执行一些类似向导的操作。为了处理向导,客户端需要服务器提供的反馈。


我们开始讨论这种方法的有状态或无状态 Web 服务。我结合自己的经历做了一些研究,这让我想到了后面提到的问题。

无状态 Web 服务具有以下属性(在我们的例子中):

+ high scalability
+ high availability
+ high speed
+ rapid testing
- bloated contract
- implementing more logic on server-side

但是我们可以删除前两点,我们的应用程序不需要高可扩展性和可用性。

所以我们来到了有状态的 Web 服务。我读过很多博客和论坛帖子,实现有状态 Web 服务的最发明的点是:

+ simplifies contract (protocol)
- bad testing
- runs counter to the basic architecture of http 

但是几乎所有 Web 应用程序不是都有这些缺点吗? Web 应用程序使用 cookie、查询字符串、会话 ID 以及所有避免 http 无状态性的东西。

那么为什么它对网络服务如此不利呢?

Imagine a more complex CRUD application which has a three-tier-architecture and communicates over webservices. The client starts a conversation to the server and doing some wizard like stuff. To process the wizard the client needs feedback given by the server.


We started a discussion about stateful or stateless webservices for this approach. I made some research combined with my own experience, which points me to the question mentioned later.

Stateless webservices having the following properties (in our case):

+ high scalability
+ high availability
+ high speed
+ rapid testing
- bloated contract
- implementing more logic on server-side

But we can cross out the first two points, our application doesn't needs high scalability and availability.

So we come to the stateful webservice. I've read a bunch of blogs and forum posts and the most invented point implementing a stateful webservice was:

+ simplifies contract (protocol)
- bad testing
- runs counter to the basic architecture of http 

But doesn't almost all web applications have these bad points? Web applications uses cookies, query strings, session ids, and all the stuff to avoid the statelessness of http.

So why is it that bad for webservices?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

恬淡成诗 2024-09-03 21:25:24

因为在 Web 服务中保持状态很困难,如果您不非常小心和/或经验丰富,迟早您可能会遇到一些很难发现的错误。

Because keeping state in a webservice is difficult and if you aren't extremely careful and/or experienced sooner or later you might hit some very difficult to find bugs.

你穿错了嫁妆 2024-09-03 21:25:24

我在有状态的网络服务方面运气不错。他们确实感觉有点脏,因为 HTTP 之上的洞 cookie 会话是这样的;但另一方面,它们是 SOAP,所以在那时对美感到太不安是有点愚蠢的。

要记住的一件事是互操作性:如果您正在做有状态的 Web 服务,您的客户将必须支持与您所做的相同的状态理念(通常是 cookie)。但再一次——对我来说效果很好。

PS 我假设您位于一个容器中,该容器将负责为您跟踪会话。

I've had reasonable luck with stateful web services. They do feel slightly dirty because the hole cookie session thing on top of HTTP is that; but on the other hand they were SOAP, so it would be kind of stupid to get too upset about beauty at that point.

One thing to keep in mind is interoperability: if you are doing stateful web service your clients will have to support the same idea of state you do (usually cookies). But again -- worked fine for me.

P.S. I assume you are in a container that will take care of keeping track of the sessions for you.

得不到的就毁灭 2024-09-03 21:25:24

状态也是大多数错误隐藏的地方。

State is where most bugs hide, too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文