【问题标题】:CoolUtils TotalPDFPrinterX causes ASP C# site to crashCoolUtils TotalPDFPrinterX 导致 ASP C# 站点崩溃
【发布时间】:2016-09-17 18:28:12
【问题描述】:

我的公司从https://www.coolutils.com/TotalPDFPrinterX购买了 CoolUtils TotalPDFPrinterX

我从 Postman 向 API 发出 HTTP PUT,但我得到“无法得到任何响应”。

在我的 Windows 机器上运行时,PDF 打印正常,但是在服务器上,站点崩溃并且在事件日志中我收到错误“服务应用程序池的进程“[MY_APP_POOL]”未能响应 ping。进程 ID是“[MY_PROCESS_ID]”。”

这是我的 C# 代码:

PDFPrinterX ppx = new PDFPrinterX();
ppx.Print(fileName, printerName, "-ap Default");
if (ppx.ErrorMessage != null)
{
    WriteToSQL(id, false, ppx.ErrorMessage, 2);
    Console.WriteLine(ppx.ErrorMessage);
}

通过写入事件日志,我知道该站点在此行崩溃:PDFPrinterX ppx = new PDFPrinterX(); 我还用 try catch 包围了上面的代码,并且没有抛出异常。该网站仍然崩溃。

我尝试过的事情:

  • 卸载并重新安装 CoolUtils 软件
  • 让每个人都可以完全控制站点文件夹和 CoolUtils 程序文件夹
  • 使用相同的代码创建 C# 桌面应用程序。这在服务器上运行良好。只是 ASP 网站崩溃了。

有人知道是什么原因造成的吗?

【问题讨论】:

  • 检查应用程序池。这个工具的版本要求是什么。只有当您尝试new PDFPrinterX 的实例时,可能会发生冲突。我建议重新检查文档。
  • @Nkosi 我应该检查应用程序池中的哪些内容?应用程序池设置为最新版本 v4.0.30319。不幸的是,该产品的文档几乎不存在。
  • 这两个环境是什么。你说它在你的 Windows 机器上运行良好。服务器的环境如何?他们的pages 之一显示Win 2000/NT/XP/2003/Vista/7

标签: c# asp.net asp.net-mvc asp.net-web-api pdf-generation


【解决方案1】:

我在网上研究的越多,我就越倾向于说 ActiveXPDFPrinterX 中的 X 在 IIS 中托管时似乎无法正常工作.

我看过一些论坛,他们说在本地主机上调试时可以正常工作,但部署到服务器时会崩溃。

...在本地主机(Visual Studio)中使用时效果很好

他们的一个功能页面显示它需要 Win 2000/NT/XP/2003/Vista/7

您应该检查您的服务器是否支持可以与 IIS 一起工作的 ActiveX 组件。

查看他们的其他产品支持页面之一:TotalPDFConverterX

鉴于TotalPDFPrinterX 也依赖于 ActiveX,我认为以下注释也可能适用于它。

注意:安装Total PDF Converter X时注意一些细节:

  • 不要忘记在您的网络服务器帐户中注册 ActiveX。
  • Total PDF Converter X 仅支持 Internet Explorer、Mozilla 和 Firefox 浏览器。
  • ActiveX 仅适用于 32 位互联网信息服务器。不支持 64 位服务器。请改用命令行版本。

【讨论】:

  • 感谢您的回答。我会在星期二回去工作时检查一下。
【解决方案2】:

感谢@Nkosi,我找到了解决方法。

ActiveX 仅适用于 32 位互联网信息服务器。不支持 64 位服务器。请改用命令行版本。

我们的 IIS 服务器是 64 位的,所以这可能是导致网站挂掉的原因。

Buttt...命令行仍然可以在服务器上打印 PDF。

客户端代码(生成 HTTP POST):

private void SendToPrinter(string fileName, string printerName, int id, decimal documentSequence)
{
    // use http client to make a POST to the print api
    using (var client = new HttpClient())
    {
        // compile the values string to transfer in POST
        // should finish to look something like this:
        // C:\print.pdf&PRTFTW_OFIT&ValShip-155320-1
        var values = new Dictionary<string, string>
        {
            { "", fileName + "&" + printerName + "&ValShip-" + id + "-" + documentSequence},
        };

        // URL encode the values string
        var content = new FormUrlEncodedContent(values);

        // make the POST

        // DEBUG
        var response = client.PostAsync("http://localhost:54339/api/print", content);

        // retrieve the response
        var responseString = response.Result.ToString();
    }

}

服务器端代码(接收 HTTP POST):

using System;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace api.valbruna.print.Controllers
{
    public class PrintController : ApiController
    {
        // POST api/print
        public HttpResponseMessage Post(HttpRequestMessage request)
        {
            try
            {
                // parse the content recieved from the client
                var content = request.Content.ReadAsStringAsync().Result;

                // decode the content, certain characters such as 
                // '&' get encoded to URL lingo such as '%26'
                content = HttpUtility.UrlDecode(content);

                // split the string into 3 seperate parts
                String[] str = content.Split('&');

                // remove the equal sign from the first string
                str[0] = str[0].Trim('=');

                // compile the arguments command line string
                // should finish to look something like this:
                // "C:\Program Files (x86)\CoolUtils\Total PDF PrinterX\PDFPrinterX.exe" "C:\print.pdf" -p"\\PRINTERS\PRTFTW_OFIT" -ap Default -log "C:\inetpub\logs\CoolUtils\log-ValShip-155320-4.txt" -verbosity detail"
                String arguments = "\"" + str[0] + "\" -p\"\\\\PRINTERS\\" + str[1] +
                                   "\" -ap Default -log \"C:\\inetpub\\logs\\CoolUtils\\log-" + str[2] +
                                   ".txt\" -verbosity detail";

                // file location for PDFPrinterX.exe
                String file = @"C:\Program Files (x86)\CoolUtils\Total PDF PrinterX\PDFPrinterX.exe";

                // start the process
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                startInfo.FileName = file;
                startInfo.Arguments = arguments;
                process.StartInfo = startInfo;
                process.Start();

                return new HttpResponseMessage() { Content = new StringContent(content) };
            }
            catch (Exception e)
            {
                return new HttpResponseMessage() { Content = new StringContent(e.Message) };
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 2016-06-25
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多