Asynchronous Sending raises an unhandled exception (URGENT HELP REQUIRED)

Aug 15, 2013 at 12:38 PM
Hello,

I have successfully implemented an application using Jamaa Lib and Jamaa Net. Thanks to the developers.

But I am facing a problem when I use Asynchronous sending operation. An unhandled exception is being raised continuously. Would be highly appreciated if someone can help me to figure out the problem.

Please be noted. I am receiving and sending SMS using the same application. I need to send on an average 100,000 SMS per day. Simultaneously I am receiving SMS from SMSC also. Thanks in advance.

My Code snippet

namespace Transciever
{
class Program
{

    static void Main(string[] args)
    {
        SmppClient client = new SmppClient();
        MySQLConnect con = new MySQLConnect();
        TextMessage msg = new TextMessage();
        Settings settings = new Settings();
        SmppConnectionProperties properties = client.Properties;
        string sysid = ConfigurationManager.AppSettings["SystemID"];
        string pswd = ConfigurationManager.AppSettings["Password"];
        string hst = ConfigurationManager.AppSettings["Host"];
        int port = Int32.Parse(ConfigurationManager.AppSettings["Port"]);
        properties.SystemID = sysid;
        properties.Password = pswd;
        properties.Port = port ; //IP port to use
        properties.Host = hst; //SMSC host name or IP Address
        properties.SystemType = "";
        properties.DefaultServiceType = "";
        //Resume a lost connection after 30 seconds
        client.AutoReconnectDelay = 3000;
        //SmppClient client1=GetSmppClient();
        //Send Enquire Link PDU every 15 seconds
        client.KeepAliveInterval = 15000;

        //Start smpp client
        try
        {
            client.Start();

        }
        catch (Exception ex)
        {


        }
        client.MessageReceived += new EventHandler<MessageEventArgs>(client_MessageReceived);
        while (true)
        {
            client.ConnectionStateChanged += (sender, e) =>
            {

                switch (e.CurrentState)
                {

                    case SmppConnectionState.Closed:
                        // Connection to the remove server is lost

                        try
                        {
                            client.Start();

                        }
                        catch (Exception ex)
                        {

                        }

                        break;

                    case SmppConnectionState.Connected:
                        //Console.Write("Connected");
                        break;

                    case SmppConnectionState.Connecting:
                        break;

                }

            };


            String successQuery = "";
            var list = new List<smsoutbox>();
            list = con.Select("select msgID, srcMN,dstMN, msg from table where msgStatus='QUE' order by msgID desc LIMIT 500");
            int listcount = list.Count;
            int i = 0;
            if (listcount > 0 && client.ConnectionState == SmppConnectionState.Connected)
            {
                foreach (var row in list)
                {
                    i = i + 1;
                    msg.DestinationAddress = row.dstMN;
                    msg.Text = row.msg;
                    msg.SourceAddress = row.srcMN;
                    msg.RegisterDeliveryNotification = false;
                    successQuery += row.msgID.ToString() + ",";
                    try
                    {
                        client.BeginSendMessage(msg, SendMessageCompleteCallback, client);                        

                    }
                    catch (Exception ex)
                    {


                    }
                    if (i == 250)
                    {
                        try
                        {
                            if (successQuery.Length > 0)
                            {
                                successQuery = successQuery.Substring(0, successQuery.Length - 1);
                                successQuery = "update smsoutbox_bl set msgStatus='SENT' where msgID in (" + successQuery + ")";
                                con.Update(successQuery);
                                successQuery = "";
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        i = 0;
                    }//if i==250 ends

                }//foreach ends
            }//if listcount>0 ends

            if (i > 0)
            {
                try
                {
                    if (successQuery.Length > 0)
                    {
                        successQuery = successQuery.Substring(0, successQuery.Length - 1);

                        successQuery = "update smsoutbox_bl set msgStatus='SENT' where msgID in (" + successQuery + ")";
                        //dbConnection.RunSql(successQuery);
                        con.Update(successQuery);
                        successQuery = "";
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }//while loop ends
    }//main ends

    static public void client_MessageReceived(object sender, MessageEventArgs e)
    {
        //The event argument e contains more information about the received message
        TextMessage textMsg = e.ShortMessage as TextMessage; //This is the received text message
        try
        {
            MyWebRequest myRequest = new MyWebRequest("http://localhost/cde/cdeblrecv.php", "POST", "mn=" + textMsg.SourceAddress + "&msg=" + textMsg.Text + "&sc=3333");

        }
        catch(Exception ex)
        {
        }
    }

    static private void SendMessageCompleteCallback(IAsyncResult result)
    {
        SmppClient client = (SmppClient)result.AsyncState;
        client.EndSendMessage(result);
    }


}//class program ends here
}//namespace ends here
Aug 16, 2013 at 8:20 PM
Below is the exception thrown by the app.

Unhandled Exception: JamaaTech.Smpp.Net.Lib.SmppException: Exception of type 'JamaaTech.Smpp.Net.Lib.SmppException' was thrown.

Server stack trace:
at JamaaTech.Smpp.Net.Client.SmppClient.SendMessage(ShortMessage message, Int32 timeOut)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)
at JamaaTech.Smpp.Net.Client.SendMessageCallBack.EndInvoke(IAsyncResult result)
at JamaaTech.Smpp.Net.Client.SmppClient.EndSendMessage(IAsyncResult result)
at Transciever.Program.SendMessageCompleteCallback(IAsyncResult result) in d:\smpp\transciever\appTranscieverinCSharp\appTranscieverinCSharp\Program.cs:line 223
at System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(IMessage msg)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object o)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()