我試圖通過部署在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年。我很少線索...任何幫助將有助於很多。
問候, 帕ñ