WebService中的静态变量生存期 [英] static variable lifetime in WebService

查看:148
本文介绍了WebService中的静态变量生存期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有webservice,它包含一个静态变量。

我将第一条消息发送到webservice,静态变量得到

a值。如果我稍后查询网络服务(比如说1小时后)

静态变量仍然保持相同的值,或者代码

是否会被重新初始化静态变量恢复为默认值:


//静态变量默认为0

//调用webservice

//静态变量设置为1

// 1小时后调用webservice

//静态变量是什么值?


我的理解Web服务进程空间(就静态

值在服务的生命周期中持续存在。


提前致谢。


史蒂文


***通过Developersdex http://www.developersdex.com ***

Hi,

I have webservice which holds a static variable.
I send my first message into the webservice and the static variable gets
a value. If I queried the webservice at a later time (say after 1 hour)
would the static variable still hold the same value, or would the code
be re-initialised and the static variable back to the default value:

//static variable is default 0
//Call webservice
//static variable is set to 1
//Call webservice 1 hour later
//What value is static variable?

My understanding of the webservice process space (in terms of static
vars) was that it matched a windows service, where a static variable
value persisted for the lifetime of the service.

Thanks in advance.

Steven

*** Sent via Developersdex http://www.developersdex.com ***

推荐答案

1月10日上午10:04,Steven Blair< steven.bl ... @ btinternet.comwrote:


< snip>
On Jan 10, 10:04 am, Steven Blair <steven.bl...@btinternet.comwrote:

<snip>

我对webservice进程空间的理解(就静态而言)
vars)它与Windows服务匹配,其中静态变量

值在服务的生命周期中持续存在。
My understanding of the webservice process space (in terms of static
vars) was that it matched a windows service, where a static variable
value persisted for the lifetime of the service.



它在AppDomain的生命周期内持续存在。但是,ASP.NET可能会出于各种原因回收AppDomains,这时你的变量的价值将会丢失。


Jon

It''s persisted for the lifetime of the AppDomain. However, ASP.NET may
recycle AppDomains for various reasons, at which point the value of
your variable will be lost.

Jon


Jon


谢谢,我现在已经关闭了IIS中的回收,似乎是

现在工作正常。


***通过Developersdex发送 http://www.developersdex.com ***
Jon

Thanks, I have now turned off the recycling in IIS and seems to be
working fine now.

*** Sent via Developersdex http://www.developersdex.com ***


请记住IIS回收是有原因的...如果您需要

持久化状态,那么或许可以考虑使用数据库?或者

或者通过Windows服务托管,而不是IIS。后者很容易为WCF做,但对于asmx来说却是一个小小的转折点。风格的网络服务。


但数据库将是我的第一直觉...


Marc
Just remember that IIS recycling is there for a reason... if you need
persisted state, then perhaps consider using a database? Or
alternatively host via a windows service, not IIS. The latter is easy
to do for WCF, but a little tricker for an "asmx" style web-service.

But a database would be my first instinct...

Marc


这篇关于WebService中的静态变量生存期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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