使用FAXCOMEXLib与Windows XP计算机在.Net 2005 2.0版中发送传真

I finally figured out a combination of things that allow the Microsoft Fax Service COM Type Library to work in ASP.NET.  I just kept trying different things, and finally got it.  If you're having this problem, try the following:

我终于弄清楚了允许Microsoft传真服务COM类型库在ASP.NET中工作的各种组合。 我只是不断尝试不同的东西,终于明白了。 如果遇到此问题,请尝试以下操作:

Be sure you have a PDF viewer installed on the computer, for all PDF, FDF types.  You can use FoxIT reader, which is free, or Adobe Acrobat, which is also free.   I personally got it working with Foxit.

确保您在计算机上安装了适用于所有PDF,FDF类型的PDF查看器。 您可以使用免费的FoxIT阅读器,也可以使用免费的Adobe Acrobat。 我个人与Foxit合作。

You need the Interop library as a reference in your program.  Go to "Add a Reference" to your program, choose the "COM" tab, then look for the following: "Microsoft Fax Service Extended COM Type Library".  It is listed under M for Microsoft, not under F for faxing.  The other library under F is WRONG--do not use this.

您需要Interop库作为程序中的参考。 转到“向程序添加引用”,选择“ COM”选项卡,然后查找以下内容:“ Microsoft传真服务扩展COM类型库”。 对于Microsoft,它列在M下,对于传真,列在F下。 F下的另一个库是WRONG-请勿使用此库。

Be sure to log on as an administrator account.  We use a domain where I work, and the Domain Admin did NOT work.  The local administrator account seemed to be the only thing I could get to work, no matter what permissions I changed on the fax printer, the directories in question, etc.

确保以管理员帐户登录。 我们使用的是我工作的域,而Domain Admin 无法工作。 无论我在传真打印机,相关目录等上更改了什么权限,本地管理员帐户似乎都是我唯一可以使用的工作。

I declared by fax server once, as a part of the class.  See below:

我曾经在传真服务器中声明过一次,作为该课程的一部分。 见下文:

    public class NightlyInvoiceCreditFaxWorkerProgram
    {
        private FAXCOMEXLib.FaxServer _faxServer = new FaxServerClass();
        public FAXCOMEXLib.FaxServer faxSrv
        {
            get
            { return _faxServer; }
            set
            { _faxServer = value; }
        } 
       

Then I used code like this, to access:

然后,我使用如下代码访问:

       NightlyInvoiceCreditFaxWorkerProgram nws = new NightlyInvoiceCreditFaxWorkerProgram();
            try
            {
                nws.faxSrv = new FaxServerClass(); 

                nws.faxSrv.Connect(""); 
        

Because I wrote this into a Windows service, I wrote many events to the Windows event log to see where I was hanging up.  This is a big part of the programming, so you know what's going on.

因为我将此内容写入Windows服务,所以我将许多事件写入Windows事件日志中以查看挂断的位置。 这是编程的重要组成部分,因此您知道发生了什么。

Then I used this code to listen for events:

然后,我使用以下代码侦听事件:

                nws.faxSrv.ListenToServerEvents(FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetOUT_QUEUE); 
                nws.faxSrv.OnOutgoingJobAdded += new FAXCOMEXLib.IFaxServerNotify_OnOutgoingJobAddedEventHandler(faxSrv_OnOutgoingJobAdded);
                nws.faxSrv.OnOutgoingJobChanged += new FAXCOMEXLib.IFaxServerNotify_OnOutgoingJobChangedEventHandler(faxSrv_OnOutgoingJobChanged);
                nws.faxSrv.OnOutgoingJobRemoved += new FAXCOMEXLib.IFaxServerNotify_OnOutgoingJobRemovedEventHandler(faxSrv_OnOutgoingJobRemoved); 
          

I used the code below for each item I needed to fax, since I send many items at once as a part of a nightly faxing routine:

我将下面的代码用于需要传真的每个项目,因为在夜间传真例程中,我一次发送了许多项目:

        try {
         FaxDocument faxDoc = new FaxDocumentClass();
         faxDoc.Priority = FAX_PRIORITY_TYPE_ENUM.fptHIGH;
         faxDoc.ReceiptType = FAX_RECEIPT_TYPE_ENUM.frtNONE; 

        //THIS CODE IS TO MAKE SURE THE FILE IS NOT IN USE WHEN WE TRY TO ATTACH AND THEN SEND
        ReadFile:
            FileStream fs = null;
            try
            {
                fs = File.OpenRead(attachmentPath); 
            }
            catch (IOException)
            {
                InvoiceCreditFaxServiceExVersion.WriteEventToWindowsLog("InvoiceCreditFaxAndEmailServiceExVersion", "Waiting for file to clear", EventLogEntryType.Information, 3);
                goto ReadFile;
            }
            finally
            {
                InvoiceCreditFaxServiceExVersion.WriteEventToWindowsLog("InvoiceCreditFaxAndEmailServiceExVersion", "File finally clear", EventLogEntryType.Information, 3);
                if (fs != null)
                {
                    fs.Close();
                    fs.Dispose();
                    fs = null;
                }
            } 
            faxDoc.Body = attachmentPath;
            faxDoc.Subject = thisItem.InvoiceNumber; 
            faxDoc.DocumentName = thisItem.RecipientName + " - Invoice: " + thisItem.InvoiceNumber; 
            faxDoc.Recipients.Add(thisItem.FaxNumber, thisItem.RecipientName); 
            object garb = faxDoc.Submit(faxSrv.ServerName); 
            InvoiceCreditFaxServiceExVersion.WriteEventToWindowsLog("InvoiceCreditFaxAndEmailServiceExVersion", "Successful Fax Send!!", EventLogEntryType.Information, 10); 
            returnString = "Send Success for Item ID: " + thisItem.ID.ToString() + " for: " + thisItem.RecipientName + "  " + thisItem.InvoiceNumber + " "; 
            faxDoc = null;
            
        }catch (System.Runtime.InteropServices.COMException ce)
            { 
                InvoiceCreditFaxServiceExVersion.WriteEventToWindowsLog("InvoiceCreditFaxAndEmailServiceExVersion", "Error connecting to fax server.  Error Message: " + ce.Message + " " + ce.StackTrace, EventLogEntryType.Information, 5);
            }
        

And, finally the event handlers for the fax server:

并且,最后是传真服务器的事件处理程序:

        private static void faxSrv_OnOutgoingJobRemoved(FAXCOMEXLib.FaxServer pFaxServer, string bstrJobId)
        {
            InvoiceCreditFaxServiceExVersion.WriteEventToWindowsLog("InvoiceCreditFaxAndEmailServiceExVersion", "Job Removed to outbound queue.", EventLogEntryType.Information, 4);
        } 
        private static void faxSrv_OnOutgoingJobChanged(FAXCOMEXLib.FaxServer pFaxServer, string bstrJobId, FAXCOMEXLib.FaxJobStatus pJobStatus)
        {
            InvoiceCreditFaxServiceExVersion.WriteEventToWindowsLog("InvoiceCreditFaxAndEmailServiceExVersion", "There was a fax changed to the outgoing queue.  WAITING UNTIL FINISHED SENDING", EventLogEntryType.Information, 4); 
            while (pJobStatus.Status != FAXCOMEXLib.FAX_JOB_STATUS_ENUM.fjsCOMPLETED)
            {
                //loop until this job is completed, then go back to the program
            }
        } 
        
        private static void faxSrv_OnOutgoingJobAdded(FAXCOMEXLib.FaxServer pFaxServer, string bstrJobId)
        {
            InvoiceCreditFaxServiceExVersion.WriteEventToWindowsLog("InvoiceCreditFaxAndEmailServiceExVersion", "There was a fax added to the outgoing queue.", EventLogEntryType.Information, 4);
        }
        

The class I used was:

我使用的课程是:

using FAXCOMEXLib;

This seems to work perfectly--it queues up the items into the Windows Fax Viewer, which then takes care of all the rest of the stuff.  If you have any specific questions about this process feel free to let me know.  I'm glad I was able to figure it out (finally), as the documentation online is terrible for this type of thing.

这似乎工作得很完美-将项目排入Windows传真查看器,然后由它处理所有其余的工作。 如果您对此过程有任何具体疑问,请随时告诉我。 我很高兴能够(最终)弄清楚这一点,因为在线文档对于此类事情很糟糕。

Compatibility is only verified in Windows XP--I didn't try with Vista or 7.

仅在Windows XP中验证了兼容性-我没有尝试过Vista或7。

翻译自: https://www.experts-exchange.com/articles/2683/Using-FAXCOMEXLib-to-send-a-fax-in-Net-2005-version-2-0-with-a-Windows-XP-computer.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值