Hi Everyone,
I am a C++ DLL which is a 3rd Party component for some processing. Before using of the methods of this component, there is some initalization which have to take place. As this initalization process sometimes can take up to 30 to 40 mins, we have a scheduler to call a WebServices which will call the initalization of this components early in the morning before the users start using the system.
The rest of the methods are being exposed to the client via Web Services (Windows Client will call the Web Services and the Web Services will call the C++ DLL indirectly). If I only have 1 client running all the time, I have no issue. However if I have multiple clients accessing the web services (but parameter being passed are different), I notice that the component get re-initalized all the time (this caused my web services not being able to process and return no result). Please advise me what is going on behind the web services? Can I use this architecture to expose the DLL? Or do I have to use other mechanism to solve this?
Best Regards
Sindy Lee
I don't suppose you can rewrite the code for that DLL, so you have to rewrite your web service to be idempotent. You have to keep a "tab" somewhere to inform the web service that processing is already underway, so it need no invoke the DLL's initialisation process again.
The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral
Errm, how do I do that?
Hi,
I just discovered that the C++ DLL is not actually a COM object, (I have to use DLLImport inorder to call the methods provided by the DLL). I also realise that if the web services is not being called by multiple user, I have no issue. However it the web service is invoked by the 2nd Client before the 1st Client has completed the method, the C++ DLL will crash. Please advise what can I do about this. When this happen, I also encounter the following Error: Problem accessing web service: The underlying connection was closed: An unexpected error occurred on a receive.
Your web service should either store a flag in a global static object that will handle the initialization work.
public class ComponentInitialization{ private static bool _isInitializing = false;
private ComponentInitialization() {}
public static void Initialize() { if (_isInitializing) return;
_isInitializing = true; // Call DLLImport function here }}
The caveat here is, if for some reason the web site or web application running the web service gets restarted, the flag it keeps for this indication will be lost. That should not happen very often, but if it is that critical then a more persistent storage is required for the flag.
Thank you. I solved this by using Synclock