Reputation:
I have an issue which I came across today which I am hoping someone may be able to to answer. I may be missing something and I don't have the code in front of me right now so am remembering this from memory.
I have a .NET MVC web application which has two layers, a UI layer and a service layer (WCF service). The UI layer has a service reference to the WCF service.
The UI layer caches some data into static variables on Application_Start in the global.asax file. These static variables are within a class in a referenced shared class library.
My WCF layer also references this class library and the static variables mentioned.
Both these layers are installed on separate servers so under their own IIS instance.
Is there any way that my WCF service could access the data in the static variables populated by the UI layer? I would have thought the service layer has its own instance of the referenced assembly and therefore the variables within it belong to itself only?
The reason I ask is this. There used to be a global.asax file on the service layer also which I recently removed which also used to populate the static variables in the shared library.
On removing this global.asax file completely from the service layer, it was still able to access the data populated by the UI layer (at least i think it was). The application would still function for a certain period of time, when left inactive (i think) these variables in the service layer became NULL and I was getting null reference exceptions.
The only way to populate the variables again was to restart the UI layer application pool. The application then worked again for some time and the repeated.
I am unsure if what I am explaining is possible in which case I am missing something or if anyone knows why this might be happening?
Upvotes: 0
Views: 1221
Reputation: 152566
Static variables are only static within an AppDomain. When IIS shuts down the App Pool (due to inactivity, etc.) those static values will be gone.
I would reference the static variables in your WCF project and then add services for the WCF layer to use to get those static values.
Upvotes: 1