views:

335

answers:

5

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

+3  A: 

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.

FlySwat
Well i have this service that request data from database every second since this cause a big perf problem and all the user will get the same data from the service i thought a singleton would be a good idea
Yassir
The service is called every second, or the service is making a database request every second?
FlySwat
@flyswat : both
Yassir
+1  A: 

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

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

Axl
+1  A: 

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.

Steven Sudit
+3  A: 

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?

Rich Rodriguez
+1  A: 

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.

John Saunders