I'm saving the messageId inside my "Outbox" table for later user. I'm updated "Outbox" records' Status by checking one by one. To update the record I need to get the current delivery status of the message, from SMSC. I'm using a windows service to run status check of delivery in a scheduled time period.
Each every run of windows service I need to call back delivery message from SMSC by using the saved messageId.
But in my implementation the Delivery Status is not updated when I called evDeliverSm function. My implementation is given below.
PS: My SMSC is allow delivery reports.
Code: Select all
public static IList<SubmitSmResp> ConnectToInet(string sourceAddress, string DestinationAddress, string Message)
{
try
{
SmppClient client = new SmppClient();
IList<SubmitSmResp> list = null;
SubmitSm sm = new SubmitSm();
client.Connect("#IP", #PORT);
if (client.Status == Inetlab.SMPP.Common.ConnectionStatus.Open)
{
client.Bind("UserName", "Password", Inetlab.SMPP.Common.ConnectionMode.Transceiver);
if (client.Status == Inetlab.SMPP.Common.ConnectionStatus.Bound)
{
client.AddrTon = 5;
list = SendAsync(sourceAddress, DestinationAddress, Message, client);
client.evDeliverSm += new Inetlab.SMPP.Common.DeliverSmEventHandler(OnDeliverSm);
}
client.Disconnect();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
Code: Select all
private static IList<SubmitSmResp> SendAsync(string source, string Destination, string message, SmppClient client)
{
IList<SubmitSmResp> list = client.Submit(
SMS.ForSubmit().From(source).To(Destination).Text(message).DeliveryReceipt().Coding(DataCodings.Default)
);
//Database saves and implementations
UsersContext db = new UsersContext();
var dn = db.UserDNs.Where(a => a.DNumber == source).FirstOrDefault();
var company = db.Companies.Find(dn.CompanyUserId);
//Save Message
int messegeID = db.SMSOutboxes.OrderByDescending(a => a.SmsID).First() == null ? 1 : db.SMSOutboxes.OrderByDescending(a => a.SmsID).First().SmsID + 1;
SMSOutbox sms = new SMSOutbox { TextMessage = message, CompanyUserId = company.CompanyID, DestinationAddress = Destination, ExpireDate = DateTime.Now.AddDays(2), Priority = 1, SentTime = DateTime.Now, SourceAddress = source, Status = "Sent", SubmitDate = DateTime.Now, SMSReference = list[0].MessageId };
db.SMSOutboxes.Add(sms);
db.SaveChanges();
foreach (var sm in list)
{
sm.Sequence = client.SequenceGenerator.NextSequenceNumber();
SaveSequenceForMessage(messegeID, list[0].Sequence);
}
return list;
}
Code: Select all
private static void OnDeliverSm(object sender, DeliverSm data)
{
Debug.Print(data.Receipt.SubmitDate.ToString());
ChangeMessageStatus(data.Receipt.MessageId, data.Receipt.State, data.Receipt.SubmitDate, data.Receipt.DoneDate);
}
How I can get Deliver message Data - State, SubmitDate, DoneDate by triggering evDeliverSm function. Currently me evDeliverSm function is not firing at all. How must I implement it to get the delivery message successfully.
Thank you for your time.