WCF绑定-wsHttpBinding使用会话?

发布于 2024-08-03 19:58:50 字数 202 浏览 4 评论 0原文

上一个线程中,一位受访者表示使用 wsHttpBinding 使用了会话。由于我在群集 IIS 环境中工作,我应该禁用此功能吗?据我所知,会话不能在集群中工作。

如果我需要禁用此功能,我该怎么做?

In a previous thread one of the respondents said that using wsHttpBinding used a session. Since I'm working in a clustered IIS environment, should I disable this? As far as I know, sessions don't work in a cluster.

If I need to disable this, how do I go about it?

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

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

发布评论

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

评论(1

So尛奶瓶 2024-08-10 19:58:50

那可能就是我:-) 默认情况下,您的服务和使用的绑定将决定会话是否发挥作用。

如果您不执行任何操作并使用 wsHttpBinding,您将拥有一个会话。如果你想避免这种情况,你应该:

  • 切换到另一个协议/绑定 在适当的地方
  • 用 SessionMode 属性装饰你的服务契约

如果你想停止服务使用会话,你可以这样做:

[ServiceContract(Namespace="....", SessionMode=SessionMode.NotAllowed)]
interface IYourSession
{
....
}

并且你可以装饰具有适当实例上下文模式的服务类属性:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
class YourService : IYourService
{
  ....
}

有了这个,您应该非常安全,不会收到任何会话。

马克

That probably was me :-) By default, your service and the binding used will determine if a session comes into play or not.

If you don't do anything, and use wsHttpBinding, you'll have a session. If you want to avoid that, you should:

  • switch to another protocol/binding where appropriate
  • decorate your service contracts with a SessionMode attribute

If you want to stop a service from ever using a session, you can do so like this:

[ServiceContract(Namespace="....", SessionMode=SessionMode.NotAllowed)]
interface IYourSession
{
....
}

and you can decorate your service class with the appropriate instance context mode attributes:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
class YourService : IYourService
{
  ....
}

With this, you should be pretty much on the safe side and not get any sessions whatsoever.

Marc

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