D
depalau
I'm running into some issues on maintaining a static variable across
the lifetime of a web service and I was wondering if anyone could help.
Background:
We have developed a C#/1.1 web service running on IIS 5/6 that
interfaces with a 3rd party DLL referenced by using the DLLImport
attribute.
Interacting with this 3rd party software through this dll requires an
initialization call to it which prepares it for subsequent functional
calls. Once all of our functional calls are made, we need to call
another dll function to close it's resources (it is a license based
application).
Due to the amount of resources needed by this 3rd party software and
the amount of web service calls made against it, it is recommened that
we only initialize it once and 'close' it only when our web service
gets recycled by IIS after a period of inactivity. Initializing this
dll returns a number that we use to perform any functionality call and
to close the software (serverID).
I have placed the call to initialize in the global.asax
Application_Start method and the call to close in the Application_End
method.
Our code looks a little like:
public class 3rdParty
{
public static short serverID;
public static void Initialize()
{
Close();
serverID = OpenServer();
}
public static void Close()
{
if (serverID > 0)
{
CloseServer(serverID);
}
}
[DllImport("3rdParty2.DLL", EntryPoint ="OpenServer",
ExactSpelling = false, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern short OpenServer();
[DllImport("PCMSRV32.DLL", EntryPoint = "CloseServer",
ExactSpelling = false, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int CloseServer(short serverID);
}
In the global.asax file:
protected void Application_Start(Object sender, EventArgs e)
{
3rdParty.Initialize();
}
protected void Application_End(Object sender, EventArgs e)
{
3rdParty.Close();
}
What is happening is that if we have a lull in access to the web
service, IIS will recycle the app domain. The next time the web
service gets started up, it will attempt to call OpenServer() again,
but since CloseServer() was never called, this 3rd party software won't
accept another OpenServer call until it is closed with the previous
serverID.
Am I going about this the right way by having a static serverID
variable? Should I be storing this value somewhere else for access?
Any input would be greatly appreciated.
Thanks,
-David
the lifetime of a web service and I was wondering if anyone could help.
Background:
We have developed a C#/1.1 web service running on IIS 5/6 that
interfaces with a 3rd party DLL referenced by using the DLLImport
attribute.
Interacting with this 3rd party software through this dll requires an
initialization call to it which prepares it for subsequent functional
calls. Once all of our functional calls are made, we need to call
another dll function to close it's resources (it is a license based
application).
Due to the amount of resources needed by this 3rd party software and
the amount of web service calls made against it, it is recommened that
we only initialize it once and 'close' it only when our web service
gets recycled by IIS after a period of inactivity. Initializing this
dll returns a number that we use to perform any functionality call and
to close the software (serverID).
I have placed the call to initialize in the global.asax
Application_Start method and the call to close in the Application_End
method.
Our code looks a little like:
public class 3rdParty
{
public static short serverID;
public static void Initialize()
{
Close();
serverID = OpenServer();
}
public static void Close()
{
if (serverID > 0)
{
CloseServer(serverID);
}
}
[DllImport("3rdParty2.DLL", EntryPoint ="OpenServer",
ExactSpelling = false, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern short OpenServer();
[DllImport("PCMSRV32.DLL", EntryPoint = "CloseServer",
ExactSpelling = false, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int CloseServer(short serverID);
}
In the global.asax file:
protected void Application_Start(Object sender, EventArgs e)
{
3rdParty.Initialize();
}
protected void Application_End(Object sender, EventArgs e)
{
3rdParty.Close();
}
What is happening is that if we have a lull in access to the web
service, IIS will recycle the app domain. The next time the web
service gets started up, it will attempt to call OpenServer() again,
but since CloseServer() was never called, this 3rd party software won't
accept another OpenServer call until it is closed with the previous
serverID.
Am I going about this the right way by having a static serverID
variable? Should I be storing this value somewhere else for access?
Any input would be greatly appreciated.
Thanks,
-David