有状态 WCF Web 服务 [英] Stateful WCF Web Service

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

问题描述

我是 WCF 的新手,我一直在尝试使用 Web 服务中的会话状态,我设法使用 编号 of 文章.

I'm new to WCF and I've been trying to use the Session state in Web Services, which I managed to get working with a number of articles.

但这些文章都遵循 .net 2.0 方法,因为新的 WCF 服务引用默认没有 CookieContainer.

But these articles all follow the .net 2.0 approach, as the new WCF Service References do not have a CookieContainer by default.

使用有状态网络服务的新学校方式是什么?

What is the new school way of using stateful web services?

(不使用反向方法,例如使用 wsdl.exe 工具或 2.0添加 Web 服务"路线生成代码.)

(Without using backwards approaches, such as code generation with the wsdl.exe tool or the 2.0 "Add Web Service" route.)

推荐答案

一句话:不要

服务应该尽可能无状态 - 它让生活变得更轻松.

Services should be stateless whenever possible - it makes life just that much easier.

如果你需要在调用之间保持状态,把它放在一个持久化容器中,例如一个数据库,并报告下一次调用时可以找到的 ID.

If you need to keep state between calls, put it in a persistance container, e.g. a database, and report back the ID under which it can be found for the next call.

马克

如果您真的必须保持会话(真的吗?请考虑两次 - 更好的是:三次) - 那么 WCF 提供针对某些绑定的每次会话调用(协议).

If you really must keep session (really?? Think about it twice - better yet: three times) - then WCF offers per-session calls on certain bindings (protocols).

最接近 ASMX 网络服务的 basicHttpBinding 不支持会话.对于面向 Internet 的应用程序,您需要使用 wsHttpBinding,对于面向内部网的内部服务,您需要使用 netTcpBinding.

The basicHttpBinding which is closest to ASMX webservices for one does not support sessions. You'll need to use wsHttpBinding for internet-facing apps, or netTcpBinding for internal intranet-oriented services.

查看 MSDN 文档,了解如何使用 WCF 会话.

Check out the MSDN docs on using sessions with WCF.

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

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