有状态 Web 服务有多好和/或有多必要? [英] How good and/or necessary are Stateful Web Services?

查看:40
本文介绍了有状态 Web 服务有多好和/或有多必要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们在实际项目中看到什么样的服务器?

What kind of server do you people see in real projects?

1) Web 服务必须是无状态的:基本上,您必须在每个请求中发送用户名/密码,每个请求都必须使用 HTTPS,如果需要,我将每次都进行身份验证并加载用户对象.

1) Web Services MUST be stateless: Basically you must send username/password with every request, every request must use HTTPS and I will authenticate and load the User object everytime if needed.

2) Web 服务的会话:就像在 Web 容器中一样,因此我至少可以保存经过身份验证的 User 对象并具有类似于会话 ID 的内容,因此我不需要在每个请求.

2) A Session for Web Services: like in a web container so I can at least save the authenticated User object and have something similar to a session ID so I don't need to authenticate, load and check the User on every request.

3) Sticky Service(跨请求的持久服务):https://jax-ws.dev.java.net/nonav/2.1/docs/statefulWebservice.html

3) Sticky Service (persistent service across requests): https://jax-ws.dev.java.net/nonav/2.1/docs/statefulWebservice.html

我了解有状态服务(以及 Web 应用程序会话)的可扩展性问题,但有时您必须拥有某种状态,例如购物车.但是您也可以将此状态放入数据库中(使用后端作为一种会话argh)或将整个状态传递给客户端(客户端负责重新发送整个购物车).

I understand the scalability problems of stateful services (and of web application sessions), but sometimes you must have some kind of state, for example for a shopping cart. But you can also put this state in the database (use the back-end as a kind of session argh) or passing the entire state to the client (the client becomes responsible for resending the entire shopping cart).

事实是,至少对于 Web 应用程序,会话在许多情况下都有很大帮助.如果您的系统接受如果他的 Web 服务器发生故障,用户必须重新开始做他正在做的任何事情",则可以忽略可扩展性问题,或者如果这是不可接受的,您可以尝试会话集群.

The truth is, at least for web applications, the session helps a lot in many situations. Scalability issues can be ignored if your system accepts that "the user must start over doing whatever he is doing if his web server happens to go down" or you can try a session cluster if that's unacceptable.

Web 服务如何?我倾向于得出结论,Web 服务与 Web 应用程序非常不同,并接受选项 1)(始终是无状态的),但根据实际项目经验听取其他意见会很高兴.

How it is for web services? I am inclined to conclude that web services are very different than web applications and accept option 1) (always stateless), but it would be nice to hear other opinions based on real project experience.

推荐答案

理想情况下,网络服务(和网站)应该是无状态的.

Ideally webservices (and web sites) should be stateless.

不幸的是,这需要经过深思熟虑的问题域和明确的关注点分离.

Unfortunately this takes very well thought out problem domain, and clear separation of concerns.

我发现在实践中大多数现实世界的网站依赖于状态,尽管这限制了它们的可扩展性.

I've found that in practice most real-world web sites depend on state even though this limits their scalability.

我还发现许多现实世界的网络服务也依赖于状态.

I've also found that many real-world web-services also rely on state.

最终,正确"的决定是针对特定问题的决定,因此编写一个依赖状态的 Web 服务可能没问题,如果可扩展性成为问题,稍后再对其进行重构.

Ultimately the 'right' decision is the one that works for the specific problem, so it's probably okay to write a webservice that relies on state, and refactor it later if scalability becomes an issue.

这篇关于有状态 Web 服务有多好和/或有多必要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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