Hi,
I am trying to integrate messaging API as part of us moving from the old system to the new one.Did some research on the forum and adapted the C# code. No matter what I try the application throws an expection at this line:
JS_Result = EM.JobSubmit(JS_Request);
The exception message is: the request failed with an empty response.
Please see below the code I am using, any help would be greatly appreciated!!
Thanks,
Roy
[WebMethod]
public void SendSMS(string PhoneNumber, string Message, string CustomerReference,string BillingCode, string Challenge)
{
string DocDataValue = "CONTENT TYPE EMAIL" + Environment.NewLine + "/SMS " + PhoneNumber + Environment.NewLine + "BC: " + BillingCode + Environment.NewLine + "Cref: " + CustomerReference + Environment.NewLine + "BT " + Environment.NewLine + Message;
//JobSubmitRequest SMS Options
// setup EMsgAPI object - EM
JobSubmitWS.JobSubmitService EM = new JobSubmitWS.JobSubmitService();
// setup Authentication objects
JobSubmitWS.RequestAuthentication reqAuth = new JobSubmitWS.RequestAuthentication();
JobSubmitWS.XDDSAuthType XDDSAuth = new JobSubmitWS.XDDSAuthType();
JobSubmitWS.UIDType uid = new JobSubmitWS.UIDType();
// init Authentication objects
// init Authentication objects
XDDSAuth.Password = "Password";
uid.Value = "username";
XDDSAuth.RequesterID = uid;
reqAuth.Item = XDDSAuth;
// Setup MessageObject
JobSubmitWS.MessageType[] JS_Message = new JobSubmitWS.MessageType[1];
JS_Message[0] = new JobSubmitWS.MessageType();
// Setup JobOptions - Voice and CRef
JobSubmitWS.JobOptionsType JS_JobOptions = new JobSubmitWS.JobOptionsType();
JobSubmitWS.EncodableStringType JS_CRef = new JobSubmitWS.EncodableStringType();
JobSubmitWS.SmsOptionsType JS_SMSOptions = new JobSubmitWS.SmsOptionsType();
// set CREF and Billing Code
JS_CRef.Value = CustomerReference;
JS_JobOptions.CustomerReference = JS_CRef;
// Set SMS Options
//JS_SMSOptions.ExpirationDaysSpecified = false;
// Set JobOptions as SMSOptions
JS_JobOptions.SmsOptions = JS_SMSOptions;
// Set Message Object
JS_Message[0].JobOptions = JS_JobOptions;
// Free Objects
JS_JobOptions = null;
JS_SMSOptions = null;
JS_CRef = null;
// Setup Documents
JobSubmitWS.DocumentType[] JS_Documents = new JobSubmitWS.DocumentType[1];
JS_Documents[0] = new JobSubmitWS.DocumentType();
// Setup reusable variables for the document
JobSubmitWS.DocDataType DocData = new JobSubmitWS.DocDataType();
DocData.format = JobSubmitWS.DocEncodingFormat.text;
DocData.Value = DocDataValue;
// Setup Document 1 - Text to be delivered to SMS Device
JS_Documents[0].Item = DocData;
JobSubmitWS.EncodableStringType myFileName = new JobSubmitWS.EncodableStringType();
myFileName.Value = "text.txt";
JS_Documents[0].Filename = myFileName;
JS_Documents[0].DocType = "text";
JS_Documents[0].ItemElementName = JobSubmitWS.ItemChoiceType.DocData;
JS_Documents[0].@ref = "TextMessage";
DocData = null;
// Setup Content
JobSubmitWS.ContentPartType[] JS_Content = new JobSubmitWS.ContentPartType[1];
JS_Content[0] = new JobSubmitWS.ContentPartType();
JS_Content[0].Item = "TextMessage";
JS_Content[0].Treatment = JobSubmitWS.TreatmentType.body;
JS_Content[0].TreatmentSpecified = true;
// Setup Destination
JobSubmitWS.SmsType[] delivery = new JobSubmitWS.SmsType[1];
delivery[0] = new JobSubmitWS.SmsType();
delivery[0].Phone = PhoneNumber;
delivery[0].@ref = "Phone Number Entered";
// Setup Report Options
JobSubmitWS.ReportOptionsType JS_Report = new JobSubmitWS.ReportOptionsType();
JobSubmitWS.ReportOptionsTypeDeliveryReport DeliveryReport = new JobSubmitWS.ReportOptionsTypeDeliveryReport();
DeliveryReport.DeliveryReportType = JobSubmitWS.MainReportTypeEnum.none;
JS_Report.DeliveryReport = DeliveryReport;
// Setup Request and JobSubmitRequest object
JobSubmitWS.Request Request = new JobSubmitWS.Request();
JobSubmitWS.Response Response = new JobSubmitWS.Response();
JobSubmitWS.JobSubmitRequest JS_Request = new JobSubmitWS.JobSubmitRequest();
JobSubmitWS.JobSubmitResult JS_Result = new JobSubmitWS.JobSubmitResult();
// Everything is Setup Prepare to Launch Job
// 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.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 (System.IO.IOException io_error)
{
//MessageBox.Show("Error - " + io_error, "Error", MessageBoxButtons.OK);
}
}
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();
}