我试图通过部署在 IIS 机器上的 WCF 服务从服务器端打印文件。以下代码在 Win 2oo3 机器上完美运行。但是同样的代码抛出了一个 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);
}
}
在为 internetexplorer 创建对象时,Com 异常如下所示。
[ERRORLOG] 由于以下错误,检索具有 CLSID {0002DF01-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80080005 服务器执行失败(来自 HRESULT 的异常:0x80080005 (CO_E_SERVER_EXEC_FAILURE))。:在 System.RuntimeTypeHandle.CreateInstance(RuntimeType 类型,Boolean publicOnly,Boolean noCheck,Boolean& canBeCached,RuntimeMethodHandleInternal& ctor,Boolean& bNeedSecurityCheck)在 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,Boolean skipCheckThis,Boolean fillCache)在 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 server 2003 中工作。我非常不知道......任何有关的帮助都会有很大帮助。
问候, 帕万 N