ASP.NET:如何往往WebService类实例化?如何使之持久对象? [英] ASP.NET: How often is WebService class instanciated? How to make a persistent object in it?

查看:337
本文介绍了ASP.NET:如何往往WebService类实例化?如何使之持久对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的问题,但我没能找到谷歌的答案。

A simple question, yet I wasn't able to find an answer in google.

如何往往是一个Web服务类实例化?难道每一次调用Web服务,是每(任意时间段)一次,是一次每别的东西吗?

How often is a web service class instanciated? Is it once per call to the web service, is it once per (arbitrary period of time), is it once per something else?

修改

我希望的生活类好长住,但好像没有。

I was hoping the class lives a good long live but seems like it does not.

问题的关键是,我已经得到了它在服务请求使用的资源和加载每次重新此资源不是一个选项(在相反,加载它曾经是一个选项是非常好的performace-及其他 - 明智的,只是单纯的'聪明')。 (没有,没有人会生气,资源没有得到阻止或什么的。)

The point is, I've got a resource which is used in serving requests, and loading this resource each time anew is not an option (on contrary, loading it once IS an option and is very good performace- and other-wise, and just simply 'wise'). (No, nobody will get upset, the resource does not get blocked or something.)

那么,如何我有一个Web服务,单一实例,其中我可以用它来服务所有请求中的对象?
很抱歉,如果问题有太明显的答案,如用一个静态变量。作为一个experinced程序员,我还没有得到很好的介绍web编程,并与一些一般概念仍然在努力。

So how do I have an object within a web service, single instance of which I can use to serve all requests? Sorry if question has a too obvious answer like "use a static variable." Being an experinced programmer, I still haven't been properly introduced to web programming and still struggle with some general concepts.

推荐答案

左右。

使用所有默认设置,网络服务类的静态变量,因为这将是一个常规的桌面应用程序,只初始化一次。即使没有人要求在很长一段时间的Web服务这是真的。您必须重新启动IIS管理器中的应用程序,让他们重新初始化。这是伟大的,正是我想要的。因此,答案很简单,只要用一个静态变量。

With all default settings, static variables of the web service class, as it would be in a regular desktop application, are only initialized once. This is true even if nobody calls the web service in a long time. You have to restart the app in IIS manager to have them re-initialized. Which is great and exactly what I wanted. So the answer is as simple as "use a static variable."

这篇关于ASP.NET:如何往往WebService类实例化?如何使之持久对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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