Question

I developed a web service (asmx) that is used to expose a proprietary system.

To send messages to my system I create a connection that is very expensive so I'd like to create this connection object once to reuse as many times as possible.

How to survive to web service lifecycle to achieve my goal?

Usually (in normal Windows application) the object is stored in a static variable.

Was it helpful?

Solution

The Object-pool pattern is your friend here. A pool contains a number of already created objects that are returned to the pool after used. On the other hand, instead of creating a new object, a one from the pool is taken if available.

There are number of different implementations easily googlable, find one and modify to suit your needs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top