有关 WCF 服务的生命周期的参考?

发布于 2024-09-25 07:12:23 字数 172 浏览 0 评论 0原文

假设我有一个简单的 WCF 应用程序,客户端调用该应用程序来获取号码。其中没有太多处理,服务契约被归因为 SessionMode=SessionMode.NotAllowed。

构造函数什么时候被调用?对象什么时候被销毁?是否根据请求调用构造函数?

是否有包含此信息的参考文档或资源?我好像找不到啊

Say I have a simple WCF application that the client calls in order to get a number. There's not much processing in it and the service contract is attributed as SessionMode=SessionMode.NotAllowed.

When is the constructor called? When is the object destructed? Is a constructor called per request?

Are there any reference documents or resources that have this information? I can't seem to find it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹤仙姿 2024-10-02 07:12:23

WCF 由 IIS 托管,因此受其生命周期规则的约束。服务类本身可能会根据需要在应用程序中创建和销毁;该类将在收到请求、调用的方法和返回的结果后构造,之后对象将离开范围并被处置/最终确定。

但是,包含您的服务的项目对于 IIS 来说看起来就像一个普通的 ActiveServer.NET Web 应用程序(查看其中应该包含的 Global.asax 文件;它包含一个 HttpApplication 类型的类,并代表 IIS 所访问的应用程序的入口点)可以用来控制它),并且 IIS 将维护这些应用程序的“池”来处理来自多个客户端的请求。只要请求不断传入,并且 IIS 没有判定应用程序已“过时”并刷新它或整个池,应用程序就会继续运行。因此,您声明的任何静态类(例如单例 IoC 容器)或添加到用作子类型的派生 HttpApplication 类的任何内容都将保留在内存中,直到应用程序被回收。

WCF is hosted by IIS, and thus subject to its lifetime rules. A service class, by itself, will probably be created and destroyed as necessary within the app; the class will be constructed upon receipt of a request, the method called, and the result returned, after which the object will leave scope and be disposed/finalized.

However, the project containing your service looks like an ordinary ActiveServer.NET web app to IIS (check out the Global.asax file that should be in it; it contains a class of type HttpApplication, and represents the entry point for the app that IIS can use to control it), and IIS will maintain a "pool" of these applications to handle requests from multiple clients. As long as requests keep coming in, and IIS doesn't decide an app has gotten "stale" and refreshes it or the entire pool, the application will continue to run. So, any static classes you declare, for instance your singleton IoC container, or anything you add to a derived HttpApplication class that you use as your child type, will remain in memory until the app is recycled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文