I have the below code for submitting SMS messages to the SMPP server, occasionally an exception is raised:
"object reference not set to an instance of an object"
can you please advise on what could be the problem and how to take care of it?
Thank you
Code: Select all
List<Inetlab.SMPP.PDU.SubmitSm> req = client.PrepareSubmit(
Inetlab.SMPP.Common.SubmitMode.ShortMessage,
Convert.ToByte(5),
Convert.ToByte(1),
SMS.sms_SenderID,
Convert.ToByte(1),
Convert.ToByte(1),
SMS.sms_MobileNo,
smsEncoding,
SMS.sms_Text);
foreach (Inetlab.SMPP.PDU.SubmitSm sm in req)
{
sm.ValidityPeriod = DateTime.Now.AddDays(2).ToString("yyMMddhhmmss000+");
}
try
{
List<Inetlab.SMPP.PDU.SubmitSmResp> resp = client.Submit(req);
if (resp.Count > 0)
{
if (resp[0].Status == Inetlab.SMPP.Common.CommandStatus.ESME_ROK)
sms_RESP = "ACK#" + resp[0].MessageId;
else
sms_RESP = "NAK#" + resp[0].Status.ToString();
}
else
{
sms_RESP = "NAK#NO RESP RECEIVED";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}