|
|
Sending Fax With RFCOMApi and .net C#
Last post 06-22-2009, 11:47 AM by jamala00. 7 replies.
-
06-18-2009, 1:49 PM |
-
jamala00
-
-
-
Joined on 06-18-2009
-
-
Posts 6
-
-
|
Sending Fax With RFCOMApi and .net C#
I have just purchased the SDK COM object. I am sure I am by far not the first person that has had to use this in .Net C# Environment. All I need to do is fax a document that is sitting on our file server. Can anybody save me hours of reading documentation and provide me a working C# Example on how to use this COM object to send a fax providing a File Path and a Fax Number...? I would imagine I have to create a Server Object, Fax Object, Attachement Object... etc, Does anybody have a working example of how to do this.
|
|
-
06-18-2009, 5:02 PM |
-
Justin.Killen
-
-
-
Joined on 06-19-2009
-
-
Posts 18
-
-
|
Re: Sending Fax With RFCOMApi and .net C#
Try this thread:
http://www.captaris.com/DeveloperProgram/forums/thread/14641.aspx
just strip the stuff off the bottom that deals with watching the email after the fact.
|
|
-
06-22-2009, 5:50 AM |
-
jamala00
-
-
-
Joined on 06-18-2009
-
-
Posts 6
-
-
|
Re: Sending Fax With RFCOMApi and .net C#
That looks like somthing that might get me started. Thanks.. Couple more questions though. Can you only send the Fax Server a .tiff doc. Will everything have to be converted to a .Tiff?.. Also, does anybody have examples of the signatures of all the calls in this .api ? I would really like to build an Abstract Class with all the calls. But in order to do that I need the signatures of all the calls. I am not finding that in the documentation. All I have for documentation is VB 6.0 references.
|
|
-
06-22-2009, 10:09 AM |
-
Justin.Killen
-
-
-
Joined on 06-19-2009
-
-
Posts 18
-
-
|
Re: Sending Fax With RFCOMApi and .net C#
You can send things other than tiffs, but from what i've read it depends on what conversion modules you have installed on your rightfax server. For example, there is a PDF module that allows sending a pdf. From personal experience, I can also tell you that not even all tif files work. Specifically, the tifs that .net produces by default (LZW compression) don't work. I've had to give up and just submit uncompressed tifs. From what I can tell, it likes CCITT group 3 and 4 and uncompressed - any others I haven't tried. There's more information in the 'COM Reference Guide', which gets installed onto the server in to <Program Files>\RightFax\Docs\COM Reference Guide.pdf. You can also find it online here: http://www.captaris.com/support/documentation/rightfax/
That should give you all of the function signatures. I too, have had problems finding adequate documentation to do simple things. The lack of examples in any documentation has been disappointing, and the thread I linked you to earlier was the best example I could find.
|
|
-
06-22-2009, 10:45 AM |
-
jamala00
-
-
-
Joined on 06-18-2009
-
-
Posts 6
-
-
|
Re: Sending Fax With RFCOMApi and .net C#
Well after paying $1600 for this SDK, I am very dissapointed. I was able to send a fax. I tried a .tif and a .pdf, and both were successful. However; the documentation provided with the SDK download was of no help. Who uses VB 6.0 anymore. I have to do a bit more research, but this code worked for me. .Net Framework 3.5 & C#.. Keep in mind this is very basic.. No Cover Page, etc.. Just sending a fax providing a fax number and document path on a file server..
FaxServer faxAPI = new FaxServer();
faxAPI.ServerName = "xxxx";
faxAPI.UseNTAuthentication = BoolType.True;
faxAPI.Protocol = CommunicationProtocolType.cpTCPIP;
object fileName = @"C:\_PlayGround\RightFaxSolution\TestPdf.pdf";
faxAPI.OpenServer();
Fax obFax = (Fax)faxAPI.get_CreateObject(CreateObjectType.coFax);
//Attachment obAttachment = (Attachment)faxAPI.get_CreateObject(CreateObjectType.coAttachment);
//obAttachment.AttachmentType = AttachmentType.aFile;
//obAttachment.FileName = fileName;
obFax.Owner = faxAPI.AuthorizationUser;
obFax.FromName = "FromName";
obFax.ToCompany = "MyCompany";
obFax.ToName = "ToCompany";
obFax.ToFaxNumber = "9999999999"; //some valid FaxNo to allow conversion
obFax.Attachments.Add(fileName, BoolType.False);
try
{
obFax.Send();
faxAPI.CloseServer();
}
catch (Exception ex)
{
string message = ex.ToString();
faxAPI.CloseServer();
}
|
|
-
06-22-2009, 11:31 AM |
-
Justin.Killen
-
-
-
Joined on 06-19-2009
-
-
Posts 18
-
-
|
Re: Sending Fax With RFCOMApi and .net C#
Don't know if this helps your situation or not, but do you mean that you paid $1,600 for the SDK, or for the software as a whole? As far as I know, the only SDK provided is the com control that is installed freely with the client install (this might have changed, we're still using an old version - 8.7).
And I agree, VB6 code is quite dated, but COM controls are still very much in use and converting such code to c# is pretty straight-forward. My only real complaint is that the examples that are given aren't very good. Even a few GOOD examples in VB would be preferable to some crappy ones in C#. Unfortunately, rightfax/captaris has provided neither.
|
|
-
06-22-2009, 11:39 AM |
-
Justin.Killen
-
-
-
Joined on 06-19-2009
-
-
Posts 18
-
-
|
Re: Sending Fax With RFCOMApi and .net C#
You mentioned that you were writing a wrapper - I've also recently been writing a wrapper in c# that i've completed. It uses some proprietary things from within our company libraries (ReportPrinter) and doesn't provide facilites for all of rightfax's features, but I think it does a fairly descent job of abstracting away from RightFax, in the case that you may want to change fax services in the future. It also has some cumbersome threading in there to force the thread into an STA (I use this from a service, which has some issues with COM). Anyway, here is the code that I am using - hope it helps:
using System; using System.Collections.Generic; using System.Data; using System.Text; using System.IO; using System.Diagnostics; using System.Windows.Forms; using System.Threading;
using AAA.DataAccess; using AAA.fileformat; using AAA.Windows.Forms;
namespace AAA.RightFax { public abstract class AaaFax { public static int MAX_COMMENTS = 9;
protected BusinessLogic m_bl = null;
protected DataTable m_dtRecipients;
protected List<string> m_comments = new List<string>();
private Dictionary<string, bool> m_dictAttachments = new Dictionary<string, bool>();
private string m_coversheet = string.Empty;
public static AaaFax CreateNew(BusinessLogic bl) { RightFax rf = new RightFax(); rf.Initialize(); rf.m_bl = bl;
return rf; }
protected AaaFax() { m_dtRecipients = new DataTable();
m_dtRecipients.Columns.Add("row_num", typeof(Int32)); m_dtRecipients.Columns.Add("to_name", typeof(string)); m_dtRecipients.Columns.Add("to_number", typeof(string)); m_dtRecipients.Columns.Add("to_company", typeof(string)); m_dtRecipients.Columns.Add("from_name", typeof(string)); m_dtRecipients.Columns.Add("from_number", typeof(string)); m_dtRecipients.Columns.Add("datetime", typeof(string)); m_dtRecipients.Columns.Add("regarding", typeof(string)); m_dtRecipients.Columns.Add("follow_up", typeof(string)); m_dtRecipients.Columns.Add("comment1", typeof(string)); m_dtRecipients.Columns.Add("comment2", typeof(string)); m_dtRecipients.Columns.Add("comment3", typeof(string)); m_dtRecipients.Columns.Add("comment4", typeof(string)); m_dtRecipients.Columns.Add("comment5", typeof(string)); m_dtRecipients.Columns.Add("comment6", typeof(string)); m_dtRecipients.Columns.Add("comment7", typeof(string)); m_dtRecipients.Columns.Add("comment8", typeof(string)); m_dtRecipients.Columns.Add("comment9", typeof(string));
m_dtRecipients.Columns.Add("recipient_object", typeof(object)); m_dtRecipients.Columns.Add("fax_id", typeof(object)); }
public string CoverSheet { set { m_coversheet = value; } get { return m_coversheet; } }
public object GetFaxIdByRecipientObject(object objRecipient) { object objRetVal = null;
foreach (DataRow dr in m_dtRecipients.Rows) { object objDtRecipient = dr["recipient_object"];
if (objDtRecipient == objRecipient) { Debug.Assert(objRetVal == null); objRetVal = dr["fax_id"]; } }
Debug.Assert(objRetVal != null); return objRetVal; }
public bool GetFaxStatusByRecipientObject(object objRecipient, ref string strStatus) { bool bSuccess = false;
object objFaxId = GetFaxIdByRecipientObject(objRecipient);
if (objFaxId != null) { bSuccess = GetFaxStatus(objFaxId, ref strStatus); }
return bSuccess; }
public string RecipientString { get { List<string> lstStrRecipients = new List<string>(); foreach (DataRow dr in m_dtRecipients.Rows) { lstStrRecipients.Add(AAA.Utility.DBNullToString(dr["to_number"])); } return string.Join(", ", lstStrRecipients.ToArray()); } }
public void AddComment(string strComment) { if (m_comments.Count < MAX_COMMENTS) { m_comments.Add(strComment); } else { throw new ArgumentOutOfRangeException(); } }
public void AddAttachment(string strFile) { AddAttachment(strFile, false); }
public void AddAttachment(string strFile, bool bDelete) { m_dictAttachments.Add(strFile, bDelete); }
public void AddRecipient(object objId, string strName, string strFaxNumber) { AddRecipient(objId, strName, strFaxNumber, string.Empty, string.Empty, string.Empty, DateTime.Now, string.Empty, string.Empty); }
public void AddRecipient(object objId, string strToName, string strToNumber, string strToCompany, string strFromName, string strFromNumber, DateTime dtDateTime, string strRegarding, string strFollowUp) { DataRow drNew = m_dtRecipients.NewRow();
drNew["row_num"] = m_dtRecipients.Rows.Count; drNew["to_name"] = strToName; drNew["to_number"] = strToNumber; drNew["to_company"] = strToCompany; drNew["from_name"] = strFromName; drNew["from_number"] = strFromNumber; drNew["datetime"] = dtDateTime; drNew["regarding"] = strRegarding; drNew["follow_up"] = strFollowUp; drNew["recipient_object"] = objId;
m_dtRecipients.Rows.Add(drNew); }
string GenerateFaxCoverSheet(DataView dvCover) {
string outputfile = lprPrint.generateTempFileName(true, "-faxcover.tiff"); SplashForm sf = new SplashForm("Loading...", true);
try { sf.DescriptionText = "Generating cover sheet...";
Dictionary<string, object> dictReportInfoAdd = new Dictionary<string, object>();
if (CoverSheet.Length != 0) { dictReportInfoAdd.Add(FileFormat.BACKGROUNDFILENAMEPARAM, CoverSheet); } else { string strFile = string.Format("{0}\\Resources\\default_faxcover_{1}.tif", System.Windows.Forms.Application.StartupPath, m_bl.CompanyNumber); if (File.Exists(strFile)) { dictReportInfoAdd.Add(FileFormat.BACKGROUNDFILENAMEPARAM, strFile); } else { strFile = string.Format("{0}\\Resources\\default_faxcover.tif", System.Windows.Forms.Application.StartupPath); }
if(File.Exists(strFile)) { dictReportInfoAdd.Add(FileFormat.BACKGROUNDFILENAMEPARAM, strFile); } else { Debug.Assert(false, "missing cover sheet file"); } } dictReportInfoAdd.Add(FileFormat.FILENAMEPARAM, outputfile);
ReportPrinter rp = new ReportPrinter(m_bl.DB, m_bl.CompanyNumber); rp.ReportFlow = ReportPrinter.REPORT_FLOW_TYPE_FORM; rp.PrintReport("FFAX", dvCover, null, false, ReportPrinter.REPORT_METHOD_TIFF, dictReportInfoAdd); } finally { sf.Close(); }
return outputfile; }
public void Send() { if (m_dtRecipients.Rows.Count == 0) { throw new ArgumentOutOfRangeException("No recipients specified."); }
// update all the records to reflect the comments... int i = 1;
foreach (string strComment in m_comments) { foreach (DataRow dr in m_dtRecipients.Rows) { dr[string.Format("comment{0}", i)] = strComment; } i++; }
List<string> lstAttachments = GenerateFaxFiles(); DataView dvRecipients = new DataView(m_dtRecipients);
ConnectToFaxServer();
foreach(DataRow dr in m_dtRecipients.Rows) { List<string> lstFiles = new List<string>();
dvRecipients.RowFilter = string.Format("row_num = {0}", AAA.Utility.FixData(dr["row_num"])); Debug.Assert(dvRecipients.Count == 1);
lstFiles.Add(GenerateFaxCoverSheet(dvRecipients));
lstFiles.AddRange(lstAttachments); SendFax(dr, lstFiles); }
//DisconnectFromFaxServer(); }
private List<string> GenerateFaxFiles() { List<string> lstStrFaxFiles = new List<string>();
foreach (string strKey in m_dictAttachments.Keys) { lstStrFaxFiles.Add(strKey); }
return lstStrFaxFiles; }
protected abstract void Initialize();
protected abstract void SendFax(DataRow drRecipient, List<string> lstStrAttachments); protected abstract void ConnectToFaxServer(); protected abstract void DisconnectFromFaxServer(); public abstract bool GetFaxStatus(object objFaxId, ref string strStatus); }
internal class RightFax : AaaFax { Thread m_ThreadForRightFaxCOMSTA = null;
protected override void Initialize() { m_ThreadForRightFaxCOMSTA = new Thread(FormForRightFaxCOMSTA.ThreadStart); m_ThreadForRightFaxCOMSTA.TrySetApartmentState(ApartmentState.STA); m_ThreadForRightFaxCOMSTA.Start(); }
protected override void ConnectToFaxServer() { FormForRightFaxCOMSTA.instance.Invoke(FormForRightFaxCOMSTA.instance.m_RightFaxConnectToFaxServerDelegate); }
protected override void SendFax(DataRow drRecipient, List<string> lstStrAttachments) { FormForRightFaxCOMSTA.instance.Invoke(FormForRightFaxCOMSTA.instance.m_RightFaxSendFaxDelegate, new object[] { drRecipient, lstStrAttachments }); }
protected override void DisconnectFromFaxServer() { FormForRightFaxCOMSTA.instance.Invoke(FormForRightFaxCOMSTA.instance.m_RightFaxDisconnectFromFaxServerDelegate); }
public override bool GetFaxStatus(object objFaxId, ref string strStatus) { bool bSuccess = true; try { strStatus = (string)FormForRightFaxCOMSTA.instance.Invoke(FormForRightFaxCOMSTA.instance.m_RightFaxGetFaxStatusDelegate, new object[] { objFaxId }); } catch (Exception ex) { bSuccess = false; strStatus = ex.Message; }
return bSuccess; } }
internal class FormForRightFaxCOMSTA : Form { RFCOMAPILib.FaxServer m_faxServer = null;
public static FormForRightFaxCOMSTA instance = null;
public RightFaxSendFaxDelegate m_RightFaxSendFaxDelegate; public RightFaxConnectToFaxServerDelegate m_RightFaxConnectToFaxServerDelegate; public RightFaxDisconnectFromFaxServerDelegate m_RightFaxDisconnectFromFaxServerDelegate; public RightFaxGetFaxStatusDelegate m_RightFaxGetFaxStatusDelegate;
public delegate void RightFaxSendFaxDelegate(DataRow drRecipient, List<string> lstStrAttachments); public delegate void RightFaxConnectToFaxServerDelegate(); public delegate void RightFaxDisconnectFromFaxServerDelegate(); public delegate string RightFaxGetFaxStatusDelegate(object objFaxId);
public void RightFaxSendFaxMethod(DataRow drRecipient, List<string> lstStrAttachments) { if (m_faxServer == null) { RightFaxConnectToFaxServerMethod(); }
RFCOMAPILib.Fax fax = m_faxServer.get_CreateObject2(m_faxServer.AuthorizationUserID, RFCOMAPILib.CreateObjectType.coFax) as RFCOMAPILib.Fax;
fax.ToName = AAA.Utility.DBNullToString(drRecipient["to_name"]); fax.ToFaxNumber = AAA.Utility.DBNullToString(drRecipient["to_number"]); fax.ToCompany = AAA.Utility.DBNullToString(drRecipient["to_company"]);
fax.FromName = AAA.Utility.DBNullToString(drRecipient["from_name"]); fax.FromFaxNumber = AAA.Utility.DBNullToString(drRecipient["from_number"]);
fax.FromVoiceNumber = AAA.Utility.DBNullToString(drRecipient["follow_up"]);
foreach (string strFile in lstStrAttachments) { fax.Attachments.Add(strFile, RFCOMAPILib.BoolType.False); }
Debug.WriteLine(string.Format("Sending to RightFax to fax # {0}", fax.ToFaxNumber)); fax.Send();
// save this for later... if (fax.Handle != 0) { Debug.WriteLine(string.Format("RightFax to fax # {0} accepted (faxid: {1})", fax.ToFaxNumber, fax.Handle)); drRecipient["fax_id"] = fax.Handle;
//try //{ // string strStatus = RightFaxGetFaxStatusMethod(fax.Handle); //} //catch (Exception ex) //{ // Debug.WriteLine(string.Format("Unable to get status: {0}", ex.Message)); //} }
fax = null; }
public void RightFaxConnectToFaxServerMethod() { m_faxServer = new RFCOMAPILib.FaxServer();
m_faxServer.ServerName = "xxxxxx"; m_faxServer.Protocol = RFCOMAPILib.CommunicationProtocolType.cpNamedPipes; m_faxServer.AuthorizationUserID = "xxxxx"; m_faxServer.AuthorizationUserPassword = "xxxxx"; m_faxServer.UseNTAuthentication = RFCOMAPILib.BoolType.False; m_faxServer.OpenServer(); }
public void RightFaxDisconnectFromFaxServerMethod() { if (m_faxServer != null) { m_faxServer.CloseServer(); m_faxServer = null; }
GC.Collect(); }
public string RightFaxGetFaxStatusMethod(object objFaxId) { if (m_faxServer == null) { RightFaxConnectToFaxServerMethod(); }
RFCOMAPILib.Fax fax = m_faxServer.get_CreateObject2(m_faxServer.AuthorizationUserID, RFCOMAPILib.CreateObjectType.coFax) as RFCOMAPILib.Fax;
fax = m_faxServer.get_Fax(objFaxId); return string.Format("{0} - {1}", fax.FaxStatus.ToString(), fax.FaxErrorCode.ToString()); }
[STAThread] static public void ThreadStart() { instance = new FormForRightFaxCOMSTA(); instance.Visible = false; instance.ShowInTaskbar = false; Application.Run(instance); }
private FormForRightFaxCOMSTA() { m_RightFaxSendFaxDelegate = new RightFaxSendFaxDelegate(RightFaxSendFaxMethod); m_RightFaxConnectToFaxServerDelegate = new RightFaxConnectToFaxServerDelegate(RightFaxConnectToFaxServerMethod); m_RightFaxDisconnectFromFaxServerDelegate = new RightFaxDisconnectFromFaxServerDelegate(RightFaxDisconnectFromFaxServerMethod); m_RightFaxGetFaxStatusDelegate = new RightFaxGetFaxStatusDelegate(RightFaxGetFaxStatusMethod); }
~FormForRightFaxCOMSTA() { if (m_faxServer != null) { m_faxServer.CloseServer();
m_faxServer = null;
GC.Collect(); } } }
}
|
|
-
06-22-2009, 11:47 AM |
-
jamala00
-
-
-
Joined on 06-18-2009
-
-
Posts 6
-
-
|
Re: Sending Fax With RFCOMApi and .net C#
Thanks for posting the code. I will take a look.. The previous post.. Yes I paid $1600, and got a CD with the RightFax COM API.iso. It has the same files that are on our Fax Server, and some documentation. I need to setup a con call with these guys, because I think I paid for something I did not have to.
|
|
|
|