I am trying to build a small application in C# which should start/stop an IIS Express worker process. For this purpose I want to use the official "IIS Express API" which is documented on MSDN: http://msdn.microsoft.com/en-us/library/gg418415.aspx
As far as I understand, the API is based (only) on COM interfaces. To use this COM interfaces I've added a reference to the COM library in VS2010 via Add Reference -> COM -> "IIS Installed Versions Manager Interface":
So far so good, but what's next? There is an IIISExprProcessUtility
interface available which includes the the two "methods" to start/stop an IIS process. Do I have to write a class which implements this interface?
public class test : IISVersionManagerLibrary.IIISExprProcessUtility
{
public string ConstructCommandLine(string bstrSite, string bstrApplication, string bstrApplicationPool, string bstrConfigPath)
{
throw new NotImplementedException();
}
public uint GetRunningProcessForSite(string bstrSite, string bstrApplication, string bstrApplicationPool, string bstrConfigPath)
{
throw new NotImplementedException();
}
public void StopProcess(uint dwPid)
{
throw new NotImplementedException();
}
}
As you can see, I'm not a professional developer. Can someone point me in the right direction. Any help is greatly appreciated.
Update 1: According to the suggestions I've tried the following code which unfortunately doesn't work:
Ok, it can be instantiated but I cannot see how to use this object...
IISVersionManagerLibrary.IIISExpressProcessUtility test3 = (IISVersionManagerLibrary.IIISExpressProcessUtility) Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("5A081F08-E4FA-45CC-A8EA-5C8A7B51727C")));
Exception: Retrieving the COM class factory for component with CLSID {5A081F08-E4FA-45CC-A8EA-5C8A7B51727C} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
This implementation works for starting/stopping IIS Express programmatically, can be used from tests.
If you modify the web.config file of the web application, IIS (including Express) will restart the app pool. This will allow you to deploy updated assemblies.
One way to modify web.config is to copy it to a new file, and then move it back.
You may want more control over IIS Express than simply restarting the app pool. But if that's all you need, this will work.
I feel you are doing it in a hard way. Take a hint from this question Automatically stop/restart ASP.NET Development Server on Build and see if you can adopt the same process.
Answering your question, I think pinvoke.net might help you. They have lot of examples as well which can help you build your solution.
Harvey Kwok had provided a good hint, since I want to tear up and tear down the service when running integration test cases. But Harvey codes is too long with PInvoke and messaging.
Here's an alternative.
And in my integration test suit with MS Test, I have
I have adopted a different solution. You can simply kill the process tree using "taskkill" and the name of the process. This works perfectly locally and on TFS 2013
Here is my solution too. It runs IIS Express with hidden windows. Manager class controls several IIS Express instances.
I need several instances. Designed manager class to control them.