I have a WCF service hosted on IIS, which references a legacy tool, via COM interface. This legacy tool is a black box for me, so I can't change its code or fix bugs in it. When I restart my WCF service, or stop it via the IIS management tool, the referenced legacy tool should shut down as well, along with all other Unmanaged data it uses, and start again on the first call from the restarted WCF service.
Everything works fine, except one function call on this legacy tool. If I call this specific function, there is probably some bug inside the tool, which prevents it from going down, even if I stop my WCF service.
I thought about a workaround in which I'll call a Process.Kill function every time my WCF service app is being disposed. My difficulty is that I can't find the suitable place to call it.
First I tried to make my Service behavior class to inherit from IDisposable, and then implement a Dispose method. The problem is that the Dispose is called every time a function finished it's flow, but I can't kill the legacy tool every call of course.
My WCF service communicates with the client app via a Net Pipe channel, so from what I understand, I can't use a Global.asax file.
My question is - Where is the suitable place to call the Process.Kill code, if I want it to be called only once, when the whole WCF service application is being disposed.
Thanks.