本文介绍了Web服务变量为web服务的生命周期共享?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能使可用于Web服务的整个生命周期的变量(对象)?

How can I make a variable (object) available for the whole lifetime of the webservice?

静态变量似乎工作但有一个其他的方式来做到这一点?

Static variable seem to work but is there an other way to do it?

推荐答案

静态变量的应用程序域的包含它们的生命周期存在。在Web服务的情况下,这通常是ASP.Net工作进程。这也就意味着,当IIS决定周期的工作进程,静态变量将不复存在。这可能是你想要的,在这种情况下,它可能是一个不错的选择。 (把静态变量是否是在给定的范围内适当asside讨论)。

Static variables exist for the lifetime of the App Domain that contains them. In the case of a web service, this is usually the ASP.Net Worker Process. What that means is that when IIS decides to cycle the worker process, your static variable will be gone. This may be what you want, in which case it is probably a good choice. (Putting asside discussions of whether or not static variables are proper in a given context).

在一个Web服务的范围,您还可以访问的(这将是一个ASMX服务......不知道是否WCF是相同与否),因此这也可以用于积攒所需的服务的生命周期的东西一个很好的选择。

Within the scope of a web service you also have access to the HttpApplicationState via the Application property (this would be an asmx service...not sure if WCF is the same or not), so this could also be a good choice for stashing something needed for the lifetime of a service.

这篇关于Web服务变量为web服务的生命周期共享?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 17:39