WCF服务默认是无状态的吗?

发布于 2024-11-07 23:21:03 字数 232 浏览 4 评论 0原文

我有一个简单的 WCF 服务,允许客户端/消费者应用程序通过提供用户名和密码来登录。如果用户名和密码都正确,WCF 服务将为客户端提供 GUID。然后,GUID 和用户名作为键/值对存储在 WCF 服务中。从这里开始,客户端将在每个请求中发送其 GUID 作为识别手段。

由于我将键/值对存储在字典/哈希图中,因此这种方法仅在 WCF 服务有状态时才有效。问题是,它们默认情况下是有状态的还是我必须做一些事情才能使它们以这种方式表现?

I've got a simple WCF service that lets clients/consumer applications log in by providing a username and password. If both the username and password are correct, the WCF service provides the client with a GUID. The GUID and the username are then stored as a key/value pair within the WCF service. From here onwards, the client sends their GUID with every request as a means of identification.

Since I'm storing the key/value pair in a Dictionary/Hashmap, this approach would only work if the WCF service is stateful. Question is, are they stateful by default or is there something I have to do to make them behave in that manner?

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

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

发布评论

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

评论(2

顾忌 2024-11-14 23:21:03

每次调用服务是 Windows Communication Foundation 默认实例化模式。因此,默认情况下,WCF 服务不维护状态。正如 Marc 所说,在 WCF 服务中保存状态存在潜在问题。我强烈建议听取他的建议。

这篇文章介绍了在 WCF 中处理实例管理的各种方法,包括如何维护状态就像你要求的那样。

Juval Lowy 的优秀 WCF 服务编程(链接)的第 4 章进行了更详细的介绍。

Per-call services are the Windows Communication Foundation default instantiation mode. So, by default, WCF services do not maintain state. As Marc stated, there are potential problems with saving state in WCF services. I strongly suggest heeding his advice.

This article describes various ways to handle instance management in WCF, including how to maintain state like you're asking for.

Chapter 4 of Juval Lowy's excellent Programming WCF Services (link) goes into much greater detail.

优雅的叶子 2024-11-14 23:21:03

它们默认是无状态的,如果可能的话,我强烈建议保持这种状态。但是,如果由于某种原因您无法启用状态,则可以启用状态。

您必须使用 wsHttpBinding 或 wsDualHttpBinding,然后设置 ServiceContract 的 SessionMode (MSDN 链接)允许或要求。
更详细的内容。

They are stateless by default and I would highly recommended keeping it that way if possible. However if for some reason you are unable to, you can enable state.

You have to use wsHttpBinding or wsDualHttpBinding and then set the SessionMode of the ServiceContract (MSDN link) to allowed or required.
goes into much greater detail.

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