2012-09-14 105 views
0

我試圖通過部署在IIS機器上的WCF服務從服務器端打印文件。 下面的代碼完美地在Win 2oo3上運行。但是相同的代碼拋出一個COM異常。對此有任何想法。我猜它與一些權限有關。 下面是代碼SHDocVw InternetExplorer打印Serverside失敗 - COM異常

public void Print(string htmlFilename, string printer, short copies) 
     { 
      string currDefault = string.Empty; 
      try 
      { 
       currDefault = GetDefaultPrinter(); 
       myPrinters.SetDefaultPrinter(printer); 
       for (int i = 0; i < copies; i++) 
       { 
        documentLoaded = false; 
        documentPrinted = false; 

InternetExplorer ie = new InternetExplorer (); 
        ie.DocumentComplete += new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(ie_DocumentComplete); 
        ie.PrintTemplateTeardown += new SHDocVw.DWebBrowserEvents2_PrintTemplateTeardownEventHandler(ie_PrintTemplateTeardown); 
        object missing = Missing.Value; 

        ie.Navigate(htmlFilename, ref missing, ref missing, ref missing, ref missing); 
        while (!documentLoaded && ie.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT) != SHDocVw.OLECMDF.OLECMDF_ENABLED) 
         Thread.Sleep(100); 


        ie.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, ref missing, ref missing); 

        ie.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref missing, ref missing); 
        while (!documentPrinted) 
         Thread.Sleep(100); 

        ie.DocumentComplete -= ie_DocumentComplete; 
        ie.PrintTemplateTeardown -= ie_PrintTemplateTeardown; 
        ie.Quit(); 
       } 
      } 
      catch { throw; } 
      finally 
      { 
       myPrinters.SetDefaultPrinter(currDefault); 
      } 
     } 

和COM異常是如下恰好同時爲InternetExplorer的一個對象。

[ERRORLOG] Retrieving the COM class factory for component with CLSID {0002DF01-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). : at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) [/ERRORLOG]

此外,如果我嘗試創建一個對象作爲InternetExplorerMedium。那麼它在2008年的工作,但不是在Win服務器2003年。我很少線索...任何幫助將有助於很多。

問候, 帕ñ

回答

0

最後我改變了我自己的邏輯。我觀察到很多與w.r.t IE不同的地方。特別是IE9。所有的DCOM分文將有所不同。所以用InternetExplorer這個名字ie = new InternetExplorer();你不能創建任何對象。它不是與權限或操作系統有關。其相關的IE版本。以上代碼僅適用於IE8。

1

檢查什麼IE版本安裝在您的2003服務器和2008服務器上。 另外,檢查其他IE版本相關的SDK運行時等,可能需要安裝不在2008盒子上,因爲不同IE版本的IE安裝不同。例如,我有一個較舊的客戶端應用程序,我必須安裝DHTMLEdit ActiveX工具包,這需要單獨的步驟,您必須搜索MSDN上的安裝例程。 還要檢查2003和2008服務器(用於運行WCF服務的帳戶)之間的帳戶和權限,看看有什麼不同。很多安全設置可能在2008年收緊。