how can i create an singleton asmx webservice ? (please don't say use WCF and WWF :D )
如何创建单例asmx webservice? (请不要说使用WCF和WWF:D)
5 个解决方案
#1
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.
长答案:对.ASMX的请求将不确定地使用新的工作线程,因此即使您使用单例模式,也不会知道单例的生命周期。
Perhaps elaborate on what you want to do, and I can guide you towards the best pattern.
也许详细说明你想做什么,我可以引导你走向最好的模式。
#2
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?
我不确定单例如何解决您的性能问题,除非您在实例中缓存数据。在这种情况下,我同意上述在服务和数据库之间引入缓存的建议。这些数据有多可变?
#3
I won't suggest WCF, but only because you asked us nicely not to.
我不会建议WCF,但只是因为你很好地问我们。
I will mention that you've found yet another reason to use WCF over ASMX. You might want to keep a list.
我会提到你已经找到了在ASMX上使用WCF的另一个原因。您可能想要保留一个列表。
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.
您可能还希望保留一个原因列表,以便在WCF上使用ASMX。您可能甚至想要使用相同的列表,原因是不升级到.NET 3.5 SP1。这不会是一个很长的清单。
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.
可能有一段时间,当管理层想知道为什么某些事情需要很长时间才能完成,当你想要将它们发送给你的列表时。
#4
You could use an ashx (HttpHandler). Implement IHttpHandler and set IsReusable to false.
你可以使用ashx(HttpHandler)。实现IHttpHandler并将IsReusable设置为false。
http://neilkilbride.blogspot.com/2008/01/ihttphandler-isreusable-property.html
#5
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.
根据您的想法,也许您可以将引擎编写为由ASMX调用的任何线程服务访问的单例。
#1
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.
长答案:对.ASMX的请求将不确定地使用新的工作线程,因此即使您使用单例模式,也不会知道单例的生命周期。
Perhaps elaborate on what you want to do, and I can guide you towards the best pattern.
也许详细说明你想做什么,我可以引导你走向最好的模式。
#2
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?
我不确定单例如何解决您的性能问题,除非您在实例中缓存数据。在这种情况下,我同意上述在服务和数据库之间引入缓存的建议。这些数据有多可变?
#3
I won't suggest WCF, but only because you asked us nicely not to.
我不会建议WCF,但只是因为你很好地问我们。
I will mention that you've found yet another reason to use WCF over ASMX. You might want to keep a list.
我会提到你已经找到了在ASMX上使用WCF的另一个原因。您可能想要保留一个列表。
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.
您可能还希望保留一个原因列表,以便在WCF上使用ASMX。您可能甚至想要使用相同的列表,原因是不升级到.NET 3.5 SP1。这不会是一个很长的清单。
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.
可能有一段时间,当管理层想知道为什么某些事情需要很长时间才能完成,当你想要将它们发送给你的列表时。
#4
You could use an ashx (HttpHandler). Implement IHttpHandler and set IsReusable to false.
你可以使用ashx(HttpHandler)。实现IHttpHandler并将IsReusable设置为false。
http://neilkilbride.blogspot.com/2008/01/ihttphandler-isreusable-property.html
#5
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.
根据您的想法,也许您可以将引擎编写为由ASMX调用的任何线程服务访问的单例。