using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace Fax { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //JobSubmitRequest Fax // setup EMsgAPI object - EM Fax.EMsgAPI_JobSubmit201101.JobSubmitService EM = new Fax.EMsgAPI_JobSubmit201101.JobSubmitService(); // setup Authentication objects EMsgAPI_JobSubmit201101.RequestAuthentication reqAuth = new EMsgAPI_JobSubmit201101.RequestAuthentication(); EMsgAPI_JobSubmit201101.XDDSAuthType XDDSAuth = new EMsgAPI_JobSubmit201101.XDDSAuthType(); EMsgAPI_JobSubmit201101.UIDType uid = new EMsgAPI_JobSubmit201101.UIDType(); // init Authentication objects XDDSAuth.Password = "password"; uid.Value = "userid"; XDDSAuth.RequesterID = uid; reqAuth.Item = XDDSAuth; // Setup MessageObject Fax.EMsgAPI_JobSubmit201101.MessageType[] JS_Message = new Fax.EMsgAPI_JobSubmit201101.MessageType[1]; JS_Message[0] = new Fax.EMsgAPI_JobSubmit201101.MessageType(); // Setup JobOptions - CREF, Billing Code, FAX Fax.EMsgAPI_JobSubmit201101.JobOptionsType JS_JobOptions = new Fax.EMsgAPI_JobSubmit201101.JobOptionsType(); Fax.EMsgAPI_JobSubmit201101.EncodableStringType JS_CRef = new Fax.EMsgAPI_JobSubmit201101.EncodableStringType(); Fax.EMsgAPI_JobSubmit201101.EncodableStringType JS_BCode = new Fax.EMsgAPI_JobSubmit201101.EncodableStringType(); Fax.EMsgAPI_JobSubmit201101.FaxOptionsType JS_FaxOptions = new Fax.EMsgAPI_JobSubmit201101.FaxOptionsType(); // set CREF and Billing Code JS_BCode.Value = "BillCode"; JS_JobOptions.BillingCode = JS_BCode; JS_CRef.Value = "CREF"; JS_JobOptions.CustomerReference = JS_CRef; // Set FaxOptions JS_FaxOptions.FaxMode = Fax.EMsgAPI_JobSubmit201101.FaxModeType.standard; JS_FaxOptions.FaxModeSpecified = true; // Set JobOptions as FaxOptions JS_JobOptions.FaxOptions = JS_FaxOptions; // Set Message Object JS_Message[0].JobOptions = JS_JobOptions; // Free Objects JS_JobOptions = null; JS_FaxOptions = null; JS_CRef = null; JS_BCode = null; // Setup Documents Fax.EMsgAPI_JobSubmit201101.DocumentType[] JS_Documents = new Fax.EMsgAPI_JobSubmit201101.DocumentType[1]; JS_Documents[0] = new Fax.EMsgAPI_JobSubmit201101.DocumentType(); // Setup reusable variables for the document Fax.EMsgAPI_JobSubmit201101.DocDataType DocData = new Fax.EMsgAPI_JobSubmit201101.DocDataType(); string File; //// Setup Document 1 - PDF File = ReadAndEncodedFile("mypdf.pdf"); DocData.format = Fax.EMsgAPI_JobSubmit201101.DocEncodingFormat.base64; DocData.Value = File; JS_Documents[0].Item = DocData; Fax.EMsgAPI_JobSubmit201101.EncodableStringType myFileName = new Fax.EMsgAPI_JobSubmit201101.EncodableStringType(); myFileName.Value = "PDF_File.pdf"; JS_Documents[0].Filename = myFileName; JS_Documents[0].DocType = "PDF"; JS_Documents[0].ItemElementName = Fax.EMsgAPI_JobSubmit201101.ItemChoiceType.DocData; JS_Documents[0].@ref = "Doc1"; DocData = null; // Setup Content Fax.EMsgAPI_JobSubmit201101.ContentsType EM_Content = new Fax.EMsgAPI_JobSubmit201101.ContentsType(); EM_Content = new Fax.EMsgAPI_JobSubmit201101.ContentsType(); Fax.EMsgAPI_JobSubmit201101.ContentPartType[] JS_Content = new Fax.EMsgAPI_JobSubmit201101.ContentPartType[1]; JS_Content[0] = new Fax.EMsgAPI_JobSubmit201101.ContentPartType(); // Setup references to documents JS_Content[0].Item = "Doc1"; JS_Content[0].Treatment = Fax.EMsgAPI_JobSubmit201101.TreatmentType.body; JS_Content[0].TreatmentSpecified = true; // Setup List Object Fax.EMsgAPI_JobSubmit201101.FaxType[] faxtype = new Fax.EMsgAPI_JobSubmit201101.FaxType[1]; faxtype[0] = new Fax.EMsgAPI_JobSubmit201101.FaxType(); faxtype[0].Phone = "9xxxxxxxxx"; JS_Message[0].Destinations = faxtype; faxtype = null; //EM_Content.DynamicContent = JS_Content; EM_Content.Part = JS_Content; JS_Message[0].Contents = EM_Content; JS_Message[0].MessageId = System.Environment.MachineName + DateTime.Now; JS_Content = null; // Everything is Setup Prepare to Launch Job // Setup Request and JobSubmitRequest object Fax.EMsgAPI_JobSubmit201101.Request Request = new Fax.EMsgAPI_JobSubmit201101.Request(); Fax.EMsgAPI_JobSubmit201101.Response Response = new Fax.EMsgAPI_JobSubmit201101.Response(); Fax.EMsgAPI_JobSubmit201101.JobSubmitRequest JS_Request = new Fax.EMsgAPI_JobSubmit201101.JobSubmitRequest(); Fax.EMsgAPI_JobSubmit201101.JobSubmitResult JS_Result = new Fax.EMsgAPI_JobSubmit201101.JobSubmitResult(); // Setup Proxy server and EMsgAPIConnect URL for posting data Set_Server_and_Proxy(EM); // Setup Reqeust Object Request.ReceiverKey = EM.Url; Request.Authentication = reqAuth; Request.RequestID = "RequestID"; JS_Request.SubmitId = "SubmitId"; // Assign Reqeust and Response objects to EM Object EM.RequestValue = Request; EM.ResponseValue = Response; JS_Request.Message = JS_Message; JS_Request.DocumentSet = JS_Documents; try { JS_Result = EM.JobSubmit(JS_Request); } catch (Exception ex) { System.Console.WriteLine(ex.Message); System.Console.Read(); return; } if (JS_Result != null) { if (JS_Result.Status.StatusCode != null) { string JobNumber; JobNumber = JS_Result.MessageResult[0].JobId.XDN + ":" + JS_Result.MessageResult[0].JobId.MRN; } } string reqfilename = "request.xml"; string emfilename = "emresponse.xml"; string resfilename = "result.xml"; //string reqfilename = "request.xml"; try { //This will output the response, result and request(if uncommented) to XML files in the //installed directory. This can be very usefull for debugging or ir help is requested from //the EMAPI support team serializeResult(reqfilename, JS_Request); serializeResult(emfilename, EM.ResponseValue); serializeResult(resfilename, JS_Result); //serializeResult(reqfilename, JS_Request); } catch (IOException io_error) { MessageBox.Show("Error - " + io_error, "Error", MessageBoxButtons.OK); } } private string ReadAndEncodedFile(string FullFileName) { string return_value; return_value = ReadAndEncodedFile(FullFileName, true); return return_value; } private string ReadAndEncodedFile(string FullFileName, bool bBase64Encode) { // read the file System.IO.FileStream inFile; byte[] binaryData; try { inFile = new System.IO.FileStream(FullFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); binaryData = new byte[inFile.Length]; long bytesRead = inFile.Read(binaryData, 0, System.Convert.ToInt32(inFile.Length)); inFile.Close(); } catch (System.Exception exp) { // Error creating stream or reading from it. System.Console.WriteLine("{0}", exp.Message); return "FAIL"; } string base64String; if (bBase64Encode) { // Convert the binary input into Base64 UUEncoded output. try { base64String = System.Convert.ToBase64String(binaryData, 0); } catch (System.ArgumentNullException) { System.Console.WriteLine("Binary data array is null."); return "FAIL"; } // done Encoding file } else { base64String = binaryData.ToString(); } return base64String; } private void Set_Server_and_Proxy(System.Web.Services.Protocols.SoapHttpClientProtocol EM) { EM.Url = "EasyLinkURL"; //the EasyLink URL to submit to. } //used to extract XML static void serializeResult(String filename, System.Object res) { System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(res.GetType()); System.IO.TextWriter w = new System.IO.StreamWriter(filename); x.Serialize(w, res); w.Close(); } } }