【发布时间】:2012-12-10 20:08:44
【问题描述】:
我正在尝试通过部署在 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 的组件的 COM 类工厂 {0002DF01-0000-0000-C000-000000000046} 由于以下原因而失败 错误:80080005 服务器执行失败(来自 HRESULT 的异常: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))。 : 在 System.RuntimeTypeHandle.CreateInstance(RuntimeType 类型,布尔值 publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) 在 System.RuntimeType.CreateInstanceSlow(布尔 publicOnly,布尔 skipCheckThis,布尔型填充缓存)在 System.RuntimeType.CreateInstanceDefaultCtor(布尔 publicOnly, 布尔型 skipVisibilityChecks,布尔型 skipCheckThis,布尔型 fillCache) 在 System.Activator.CreateInstance(Type type, Boolean 非公共)在 System.Activator.CreateInstance(类型类型) [/错误日志]
此外,如果我尝试将对象创建为 InternetExplorerMedium。然后它在 2008 年工作,但在 Win server 2003 中没有。我非常不知道......任何有关的帮助都会有很大帮助。
问候, 帕万 N
【问题讨论】:
标签: c# asp.net wcf printing shdocvw