会话变量和 Web 服务 [英] Session Variables and Web Services
问题描述
我刚刚编写了我的第一个 Web 服务,因此假设我的 Web 服务知识不存在.我想尝试从 Web 服务调用 dbClass 函数.但是我需要一些会话中的参数.有什么办法可以让我从网络服务中调用这些会话变量??
I just wrote my first web service so lets make the assumption that my web service knowlege is non existant. I want to try to call a dbClass function from the web service. However I need some params that are in the session. Is there any way I can get these call these session variables from the webservice??
推荐答案
如果您正在使用 ASP.NET Web 服务并且希望为您维护一个会话环境,您需要使用一个属性来修饰您的 Web 服务方法表示您需要会话.
If you are using ASP.NET web services and you want to have a session environment maintained for you, you need to embellish your web service method with an attribute that indicates you require a session.
[WebMethod(EnableSession = true)]
public void MyWebService()
{
Foo foo;
Session["MyObjectName"] = new Foo();
foo = Session["MyObjectName"] as Foo;
}
完成此操作后,您可以访问类似于 aspx 的会话对象.
Once you have done this, you may access session objects similar to aspx.
地铁.
这篇关于会话变量和 Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!