Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How to initialize WebService

Is there a possibility to initialize a WebService.

I'm searching for a method that runs only during first call to WebService. Is there something like it in .Net ?

like image 329
Darqer Avatar asked Aug 25 '09 14:08

Darqer


1 Answers

If you require "initialisation" the first time a given client connects to the Web Service:

Have an Initialise method that returns a token, such a a GUID, that's then required on every call made to the actual "does the work" method of your web service. You can then ensure that for that client the service is always initialised.

If you require it the first time the web service is ever called:

Add some code to your service, as a private method, that is called at the top of each public method. Within it check for the existance of something, such as a registry entry, file, database record or other persistant value. If it doesn't exist, perform your initialisation and then create the "something".

If you require it on the first call since IIS last recycled/started the Application Pool:

Have a static constructor for the class so that when it's first instantiated the static constructor runs and performs your initialisation.

like image 132
Rob Avatar answered Sep 28 '22 07:09

Rob