调度通过FAXCOMEXLib发送传真的c#控制台应用程序出错

本文关键字:真的 控制台 应用 程序出错 FAXCOMEXLib 调度 | 更新日期: 2023-09-27 18:06:11

我有一个用c#编写的控制台应用程序,使用MS Fax (FAXCOMEXLib)发送传真。如果我手动或从命令提示符运行应用程序,它会按预期工作。如果我使用Task Scheduler调度应用程序或尝试从带有计时器的服务运行,则在调用FaxDocument对象上的ConnectedSubmit2时会失败。应用程序按预期运行,获取数据,创建pdf,连接到Fax Service,填充FaxDocument属性,但是在ConnectedSubmit2上爆炸。感觉像是安全问题。运行TaskScheduler的windows帐户属于管理员组。

同样的应用程序已经在另一台Server 2008(不是R2)计算机上运行,任务调度程序没有问题。

问题服务器正在运行Microsoft server 2008 R2。

重述:如果手动运行应用程序将工作,如果从其他进程(如Task Scheduler)运行则会失败。

任何建议都是非常感谢的。谢谢你。

c#代码:

FAXCOMEXLib.FaxServer faxServer = new FAXCOMEXLib.FaxServer();
FAXCOMEXLib.FaxDocument faxDocument = new FAXCOMEXLib.FaxDocument();
ArrayList al = new ArrayList();
al.Add(orderPdfFilePath);
if (facesheetPdfFilePath != "")
    al.Add(facesheetPdfFilePath);
if (write) Console.WriteLine("Preparing to Connect to Fax Server...");
sbLog.Append("Preparing to Connect to Fax Server...'r'n");
faxServer.Connect("");
if (write) Console.WriteLine("Connected.");
sbLog.Append("Connected.'r'n");
// Add Sender Information to outgoing fax
faxDocument.Sender.Name = dr2["FacilityName"].ToString();
faxDocument.Sender.Department = dr2["TSID"].ToString();
faxDocument.Sender.TSID = Truncate(dr2["TSID"].ToString(), 20);
faxDocument.Recipients.Add(dr2["FaxNumber"].ToString(), dr2["Pharmacy"].ToString());
faxDocument.Bodies = al.ToArray(typeof(string));
faxDocument.Subject = order;
if (write) Console.WriteLine("Attempting submit to fax server...");
sbLog.Append("Attempting submit to fax server...'r'n");
// attempt send...
try
{
    object o;
    faxDocument.ConnectedSubmit2(faxServer, out o);    
    if (write) Console.WriteLine("Fax sent successfully " + DateTime.Now.ToString());
    sbLog.Append("Fax sent successfully " + DateTime.Now.ToString() + ".'r'n");
}
catch (Exception ex)
{
    if (write) Console.WriteLine("SEND FAILED! " + order + " " + DateTime.Now.ToString() + "  " + ex.Message);
    sbLog.Append("SEND FAILED! " + order + " " + DateTime.Now.ToString() + ".'r'n" + ex.Message + "'r'n" + ex.InnerException + "'r'n");
    error = true;
}

error in Event Log:

  1. System.Runtime.InteropServices。COMException (0x80070102): Operation failed.告警解释在FAXCOMEXLib.FaxDocumentClass。ConnectedSubmit2(IFaxServer pFaxServer, Object&pvFaxOutgoingJobIDs)
  2. 系统。UnauthorizedAccessException:访问被拒绝。在FAXCOMEXLib.FaxDocumentClass。ConnectedSubmit2(IFaxServer pFaxServer, Object&在elementstrtransmission . program。Main (String [] args)

调度通过FAXCOMEXLib发送传真的c#控制台应用程序出错

参见

http://blogs.msdn.com/b/dougste/archive/2011/08/30/system-runtime-interopservices-comexception-0x80070102-operation-failed-trying-to-send-a-fax-from-and-asp-net-application.aspx

比尔