如何创建单例asmx服务

发布于 2024-07-26 03:17:38 字数 53 浏览 3 评论 0原文

我如何创建一个单例 asmx web 服务? (请不要说使用 WCF 和 WWF :D )

how can i create an singleton asmx webservice ? (please don't say use WCF and WWF :D )

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

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

发布评论

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

评论(5

弃爱 2024-08-02 03:17:40

简短的回答:你不想。

长答案:对 .ASMX 的请求将不确定地使用新的工作线程,因此即使您使用单例模式,单例的生命周期也不会被知道。

也许详细说明您想要做什么,我可以引导您找到最佳模式。

Short Answer: You don't want to.

Long Answer: A request to an .ASMX is going to non deterministically use a new worker thread, so even if you used the singleton pattern, the life of the singleton will not be known.

Perhaps elaborate on what you want to do, and I can guide you towards the best pattern.

调妓 2024-08-02 03:17:40

我不确定单例如何解决您的性能问题,除非您在实例内缓存数据。 在这种情况下,我同意上面在服务和数据库之间引入缓存的建议。 这些数据的可变性到底有多大?

I'm not sure how a singleton solves your performance problem, unless you are caching data inside the instance. In that case, I'd agree with the above suggestion of introducing the cache between the service and the database. Just how mutable is this data?

向日葵 2024-08-02 03:17:40

我不会建议 WCF,但这只是因为您善意地要求我们不要这样做。

我要提到的是,您已经找到了使用 WCF 而不是 ASMX 的另一个原因。 您可能想保留一份清单。

您可能还想保留使用 ASMX 而不是 WCF 的原因列表。 由于不升级到 .NET 3.5 SP1 的原因,您甚至可能想要使用相同的列表。 这不会是一个很长的清单。

也许有一天,当管理层想知道为什么某些事情需要这么长时间才能完成时,你就会想向他们发送你的清单。

I won't suggest WCF, but only because you asked us nicely not to.

I will mention that you've found yet another reason to use WCF over ASMX. You might want to keep a list.

You might also want to keep a list of reasons to use ASMX over WCF. You might even want to use the same list for the reasons not to upgrade to .NET 3.5 SP1. It won't be a long list.

There may come a time, when Management wonders why certain things take so long to accomplish, when you'll want to send them your list.

油饼 2024-08-02 03:17:40

您可以使用 ashx (HttpHandler)。 实现 IHttpHandler 并将 IsReusable 设置为 false。

http://neilkilbride.blogspot.com/2008/01/ihttphandler- isreusable-property.html

You could use an ashx (HttpHandler). Implement IHttpHandler and set IsReusable to false.

http://neilkilbride.blogspot.com/2008/01/ihttphandler-isreusable-property.html

眼泪都笑了 2024-08-02 03:17:40

根据您想要执行的操作,也许您可​​以将引擎编写为单例,由任何服务 ASMX 调用的线程访问。

Depending on what you want to do, maybe you can write the engine as a singleton that's accessed by whatever thread services the ASMX call.

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