Delivery Report inside a windows service

.NET library for SMPP protocol
Locked
thilanka1989
Posts: 2
Joined: Wed Apr 05, 2017 5:20 am

Delivery Report inside a windows service

Post by thilanka1989 » Wed Apr 05, 2017 5:37 am

I have built a SMS Gateway by using the InetLab SMPP. The message sending is doing well via WCF web api I have created. When I call the API with required parameters the message is sent to the receiver number successfully and I'm receiving the messageId from the delivery receipt.

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.
alt
Site Admin
Posts: 985
Joined: Tue Apr 25, 2006 9:45 am

Re: Delivery Report inside a windows service

Post by alt » Thu Apr 06, 2017 7:12 am

Hi thinlanka,

SmppClient in your SMS Gateway must be always connected to SMSC.
After SendAsync you do client.Disconnect. In this circumstances evDeliverSm will be never triggered.
thilanka1989
Posts: 2
Joined: Wed Apr 05, 2017 5:20 am

Re: Delivery Report inside a windows service

Post by thilanka1989 » Thu Apr 06, 2017 8:31 am

Thank you I have solved the problem exactly like that. But when I send a message if its not delivered then the message is saved in my outbox with the messageId. Unfortunately the messageId Im getting from SubmitSm method is not equal to the messageId I've got from DeliverSm method. By the way I can update the outbox table record status to delivered when the message is delivered and DeliverSm method is triggered. But when I want to get the delivery report of the same message again. How must I bind again and get the current delivery status?
thank you for your help!
alt
Site Admin
Posts: 985
Joined: Tue Apr 25, 2006 9:45 am

Re: Delivery Report inside a windows service

Post by alt » Mon Apr 10, 2017 7:51 pm

When you send long text library sends several concatenated SubmitSm PDUs. As response you will receive the same number of SubmitSmResp with different MessageIds.

SMSC should send delivery report until it receives DeliverSmResp with Status EMSE_ROK.

Some SMSC provide also Query command.
It helps to get status for MessageId.
Locked