We have the set of the web services developed with Net 3.5 SP1 and hosted under IIS 7.5 (w2008/x64). Those web services are completely stateless and do not use any session cache. We have app pool recycled every hour. System is working under heavy load 24x7.
The web service implementation contains class library with the logic statically referenced by the web service class. All methods in web service class are like:
return new ImplementationClass();
Our implementation class has one static object with constructor which reads the data from the system catalog views from MSSQL 2008. There is also the static constructor in the implementation class which creates this static object. Web service methods call one of the method of that object which is doing some processing based on the data cached during constructor call.
The reason why we implemented it this way is because the data the object is cached is fairly static (updating one time per a few weeks). So we would like to cache it in app pool and don't read it from the database in the every web service method call.
This works just fine although one time per a few days we are getting exceptions: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> The type initializer for 'ImplementationClass' threw an exception. ---> Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The exceptions (for all sessions) last until app pool is recycled. Timeout expired could be related with SQL server, although server is up and running - other processes are working just fine.
After some time we moved the static object creation from ImplementationClass static constructor to the web methods. Basically the pattern is:
if (staticObject == null)
if (staticObject == null)
staticObject = StaticClass();
although it would not help. Now we are getting the following exception:
System.Net.WebException: The request failed with HTTP status 503: Service Unavailable.
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
with the following entry in the event log: Faulting application name: w3wp.exe, version: 7.5.7600.16385, time stamp: 0x4a5bd0eb Faulting module name: KERNELBASE.dll, version: 6.1.7600.16385, time stamp: 0x4a5bdfe0 Exception code: 0xe053534f Fault offset: 0x000000000000aa7d Faulting process id: 0x%9 Faulting application start time: 0x%10 Faulting application path: %11 Faulting module path: %12 Report Id: %13.
Again, it happens one time per a few days and last until app pool recycled.
We can change the implementation and get rid of the static object (put the object to the global cache, etc) although it would require some time and efforts.
I wonder, if you have the experience with the static objects in the web services and can give us some advice. We are not 100% sure if problem is related with the static object although it started to happen after we implement this feature