【问题标题】:SHDocVw InternetExplorer printing Serverside failing -- COM exceptionSHDocVw InternetExplorer 打印服务器端失败——COM 异常
【发布时间】: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


    【解决方案1】:

    检查您的 2003 服务器和 2008 服务器上安装了哪些版本的 IE。 此外,由于针对不同 IE 版本的不同 IE 安装,可能需要安装其他 IE 版本相关的 SDK 运行时等,但这些运行时不在 2008 盒子上。例如,我有一个较旧的客户端应用程序,我必须在其中安装 DHTMLEdit ActiveX 工具包,这需要一个单独的步骤,并且您必须在 MSDN 上查找设置例程。 还要检查 2003 和 2008 服务器之间的帐户和权限(用于运行 WCF 服务的帐户),看看有什么不同。 2008 年可能加强了很多安全设置。

    【讨论】:

      【解决方案2】:

      最后我改变了自己的逻辑。我观察到很多与 IE 不同的地方。特别是IE9。所有的 DCOM 设置都会有所不同。所以用名字 InternetExplorer ie = new InternetExplorer();你不能创建任何对象。它与权限或操作系统无关。它与IE版本有关。以上代码仅适用于 IE8。

      【讨论】:

        猜你喜欢
        • 2014-01-19
        • 1970-01-01
        • 2013-04-04
        • 2020-10-30
        • 1970-01-01
        • 1970-01-01
        • 2016-06-20
        • 2012-06-25
        相关资源
        最近更新 更多