2010-08-17 7 views
1

Windows 2003 서버를 사용하여 다양한 작업을 실행합니다. 이러한 작업 중 일부는 IIS 6 (실행, 시작, 중지)을 실행하는 웹 서버에 응용 프로그램 풀 명령을 보냅니다. 이제 IIS 7을 실행하는 Windows 2008 웹 서버가 있으며 동일한 명령을 보내려고합니다. 이것은 모두 C#을 사용하여 완료됩니다. Windows 2003 서버에서 프로그래밍 방식으로 IIS 7 서버 제어

우리가 IIS 6에 대한 명령을 보낼 때 사용하는 코드입니다 :

var methodToInvoke = "Stop"; // could be "Stop", "Start", or "Recycle" 
var co = new ConnectionOptions 
{ 
    Impersonation = ImpersonationLevel.Impersonate, 
    Authentication = AuthenticationLevel.PacketPrivacy 
}; 

var objPath = string.Format("IISApplicationPool.Name='W3SVC/AppPools/{0}'", appPoolName); 
var scope = new ManagementScope(string.Format(@"\\{0}\root\MicrosoftIISV2", machineName), co); 

using (var mc = new ManagementObject(objPath)) 
{ 
    mc.Scope = scope; 
    mc.InvokeMethod(methodToInvoke, null, null); 
} 

이 코드 때문에 기본 변화에 IIS 7 작동하지 않습니다, 그래서 우리는 현재이하려는 :

using (ServerManager serverManager = ServerManager.OpenRemote(machineName)) 
{ 
    var appPool = serverManager.ApplicationPools[appPoolName]; 
    if (appPool != null) 
    { 
     appPool.Stop(); // or app.Start() or app.Recycle() 
     serverManager.CommitChanges(); 
    } 
} 

위의 코드는 Windows 7 (및 IIS 7.5)을 실행하는 내 워크 스테이션에서 정상적으로 작동합니다. 그러나이 코드를 응용 프로그램 서버에 배포하면 작동하지 않습니다. 때문에 7은 윈도우 서버 2003 서버에서 사용할 수 없습니다 IIS 사실을

내 연구에서
System.InvalidCastException: 
Unable to cast COM object of type 'System.__ComObject' to interface type 
'Microsoft.Web.Administration.Interop.IAppHostWritableAdminManager'. 
This operation failed because the QueryInterface call on the COM component for the 
interface with IID '{FA7660F6-7B3F-4237-A8BF-ED0AD0DCBBD9}' failed due to the following error: 
Interface not registered (Exception from HRESULT: 0x80040155). 

, 이것이다 : 그것은이 오류가 발생합니다. (필자는 Microsoft.Web.Administration.dll 파일을 포함했다.)

그래서 내 질문은 : IIS 7 위의 코드는 윈도우 2003 서버에서 모든 작업 할 수

  1. 이 가능합니까?
  2. # 1에 없다면 더 나은 방법이 있습니까?

답변

2

주위를 읽는 것이 당신이 찾고있는 것을 할 수없는 것처럼 보입니다. dll 파일을 포함하는 것으로는 충분하지 않습니다. http://forums.iis.net/t/1149274.aspx에 따르면 ..

In order to use Microsoft.Web.Administration you need to have IIS installed, at the bare minimum you need to install the Configuration API's which are brought through installing the Management Tools.

Unfortunately there is no SDK that enables this and it has several dependencies on other components that wouldn't let you just take it to another machine and make it work (such as COM objects, DLL's, etc).

나는이 라운드 방법을 발견 한 경우 알고에 관심이있을 것입니다.

감사합니다.

+0

웹 서버 자체에서 해당 서버의 응용 프로그램 풀을 시작/중지/재활용하는 웹 서비스가 만들어졌습니다. 이 웹 서비스는 분명히 업데이트 할 앱 풀과 별도의 앱 풀에 있어야합니다. 매우 안전한 솔루션은 아니지만 내부 웹 서버로 작업하고 있습니다. –

+0

같은 문제로 인해 게시글에서 내가 뭘 두려워했는지 확인했습니다. 관리 API는 Windows XP에서 작동하지 않습니다. 게시물을 주셔서 감사합니다 – Jeremy

0

Microsoft.Web.Administration 그것은 프레임 워크 4가 아닌 클라이언트 프로파일에 의해 제공되었다 System.Web.dll에 의존 :

이 항목을 참조하십시오.

+1

이것은 질문에 대답하지 않습니다. –

관련 문제