I'm trying to create a prototype using this API to send fax messages. I'm using the samples at https://apiforums.easylink.com/content/c-sample-jobsubmit-sms-options-single-recipient as a reference.
Getting an exception with the message - The request failed with an empty response. Here is my code below
public static void SendFaxCopied()
{
//JobSubmitRequest Fax
// setup EMsgAPI object - EM
ELJobSubmit.JobSubmitService EM = new ELJobSubmit.JobSubmitService();
// setup Authentication objects
ELJobSubmit.RequestAuthentication reqAuth = new ELJobSubmit.RequestAuthentication();
ELJobSubmit.XDDSAuthType XDDSAuth = new ELJobSubmit.XDDSAuthType();
ELJobSubmit.UIDType uid = new ELJobSubmit.UIDType();
// init Authentication objects
XDDSAuth.Password = "password";
uid.Value = "username";
XDDSAuth.RequesterID = uid;
//Add to send to Fax2Mail
//XDDSAuth.RequesterID.aliasType = "M2F";
reqAuth.Item = XDDSAuth;
// Setup MessageObject
ELJobSubmit.MessageType[] JS_Message = new ELJobSubmit.MessageType[1];
JS_Message[0] = new ELJobSubmit.MessageType();
// Setup JobOptions - CREF, Billing Code, FAX
ELJobSubmit.JobOptionsType JS_JobOptions = new ELJobSubmit.JobOptionsType();
ELJobSubmit.FaxOptionsType JS_FaxOptions = new ELJobSubmit.FaxOptionsType();
// Set Start and End Time
//DateTime StartDateValue = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day, dateTimePicker1.Value.Hour, dateTimePicker1.Value.Minute, 0, dateTimePicker1.Value.Kind);
//DateTime EndDateValue = new DateTime(dateTimePicker2.Value.Year, dateTimePicker2.Value.Month, dateTimePicker2.Value.Day, dateTimePicker2.Value.Hour, dateTimePicker2.Value.Minute, 0, dateTimePicker2.Value.Kind);
DateTime StartDateValue = new DateTime();
StartDateValue = DateTime.Now.AddHours(1);
DateTime EndDateValue = new DateTime();
EndDateValue = DateTime.Now.AddHours(2);
ELJobSubmit.DeliveryType ScheduledDelivery = new ELJobSubmit.DeliveryType();
ScheduledDelivery.Schedule = ELJobSubmit.ScheduleType.scheduled;
ScheduledDelivery.ScheduleSpecified = true;
ScheduledDelivery.StartTimeSpecified = true;
ScheduledDelivery.StopTimeSpecified = true;
ScheduledDelivery.StartTime = StartDateValue;
ScheduledDelivery.StopTime = EndDateValue;
//JS_JobOptions.Delivery = ScheduledDelivery;
// Set FaxOptions
//JS_FaxOptions.FaxMode = ELJobSubmit.FaxModeType.fine;
//JS_FaxOptions.FaxModeSpecified = true;
// Set Retry Algo
JS_FaxOptions.DeliveryRetryPattern = "11";
ELJobSubmit.FaxCoversheetOptionType CoverSheet = new ELJobSubmit.FaxCoversheetOptionType();
CoverSheet.UseCoversheet = ELJobSubmit.YesNo.yes;
//Specify a cover sheet
//CoverSheet.CoversheetName = "f2m_default";
ELJobSubmit.EncodableStringType CS_To = new ELJobSubmit.EncodableStringType();
CS_To.Value = "Tom";
CoverSheet.CoversheetTo = CS_To;
ELJobSubmit.EncodableStringType CS_Attn = new ELJobSubmit.EncodableStringType();
CS_Attn.Value = "Mr. Smith";
CoverSheet.CoversheetAttn = CS_Attn;
ELJobSubmit.EncodableStringType CS_From = new ELJobSubmit.EncodableStringType();
CS_From.Value = "EasyLink";
CoverSheet.CoversheetFrom = CS_From;
JS_FaxOptions.FaxCoversheet = CoverSheet;
//// Set PilotLine
ELJobSubmit.FaxPilotlineOptionType PilotLine = new ELJobSubmit.FaxPilotlineOptionType();
PilotLine.PilotlineStyle = ELJobSubmit.PilotlineStyleType.none;
PilotLine.PilotlineStyleSpecified = true;
PilotLine.PilotlineText = "PILOTLINETEXT";
//JS_FaxOptions.Pilotline = PilotLine;
//// Set Orientation
//JS_FaxOptions.PageOrientation = ELJobSubmit.PageOrientationType.landscape;
//JS_FaxOptions.PageOrientationSpecified = 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;
// Setup Documents
ELJobSubmit.DocumentType[] JS_Documents = new ELJobSubmit.DocumentType[2];
JS_Documents[0] = new ELJobSubmit.DocumentType();
// Setup reusable variables for the document
ELJobSubmit.DocDataType DocData = new ELJobSubmit.DocDataType();
string File;
//// Setup Document 3 - Text
DocData = new ELJobSubmit.DocDataType();
File = ReadAndEncodedFile("This is where the contents of the file show go", true);
DocData.format = ELJobSubmit.DocEncodingFormat.text;
DocData.Value = "This is a test document";
JS_Documents[0].Item = DocData;
JS_Documents[0].Filename = new ELJobSubmit.EncodableStringType { Value = "text.txt" };
JS_Documents[0].DocType = "text";
JS_Documents[0].ItemElementName = ELJobSubmit.ItemChoiceType.DocData;
JS_Documents[0].@ref = "Doc1";
DocData = null;
// Setup Content
ELJobSubmit.ContentsType EM_Content = new ELJobSubmit.ContentsType();
ELJobSubmit.ContentPartType[] JS_Content = new ELJobSubmit.ContentPartType[1];
JS_Content[0] = new ELJobSubmit.ContentPartType();
//JS_Content[1] = new ELJobSubmit.ContentPartType();
// Setup references to documents
JS_Content[0].Item = "Doc1";
JS_Content[0].Treatment = ELJobSubmit.TreatmentType.body;
JS_Content[0].TreatmentSpecified = true;
// Setup List Object
ELJobSubmit.FaxType[] lists = new ELJobSubmit.FaxType[1];
lists[0] = new ELJobSubmit.FaxType();
lists[0].From = new ELJobSubmit.EncodableStringType() { Value = "3212131243" };
lists[0].Phone = "8008082904";
JS_Message[0].Destinations = lists;
//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
ELJobSubmit.Request Request = new ELJobSubmit.Request();
ELJobSubmit.Response Response = new ELJobSubmit.Response();
ELJobSubmit.JobSubmitRequest JS_Request = new ELJobSubmit.JobSubmitRequest();
ELJobSubmit.JobSubmitResult JS_Result = new ELJobSubmit.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;
// txtJobNumber.Text = JobNumber;
// }
//}
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(emfilename, EM.ResponseValue);
serializeResult(resfilename, JS_Result);
//serializeResult(reqfilename, JS_Request);
}
catch (IOException io_error)
{
MessageBox.Show("Error - " + io_error, "Error", MessageBoxButtons.OK);
}
}
private static void Set_Server_and_Proxy(System.Web.Services.Protocols.SoapHttpClientProtocol EM)
{
EM.Url = "https://test2messaging.easylink.com/soap/sync"; //the EasyLink URL to submit to.
}