2

我已经使用 Jamaa Lib 和 Jamaa Net 成功实现了一个应用程序。感谢开发者。

但是当我使用异步发送操作时,我遇到了一个问题。不断引发未处理的异常。如果有人可以帮助我解决问题,将不胜感激。

请注意。我正在使用同一个应用程序接收和发送 SMS。我平均每天需要发送 100,000 条短信。同时我也收到来自 SMSC 的短信。提前致谢。

我的代码片段

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 

下面是应用程序抛出的异常。

未处理的异常:JamaaTech.Smpp.Net.Lib.SmppException:抛出了“JamaaTech.Smpp.Net.Lib.SmppException”类型的异常。

服务器堆栈跟踪:

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

在 [0] 处重新引发异常:在 JamaaTech.Smpp 的 System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData) 的 System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)。 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:System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(IMessage msg) 处的第 223 行 System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink) 处 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 回调,对象状态,布尔值 preserveSyncCtx) 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue.Dispatch() 在 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue 的对象状态,布尔型 preserveSyncCtx)。 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() 处的 Dispatch()System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue 的对象状态,布尔型 preserveSyncCtx)。 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() 处的 Dispatch()

4

2 回答 2

1

您可以尝试使用 wireshark 查看原始数据包,这会让您知道出了什么问题。在我的情况下,这是一个无效的系统 ID。

于 2015-09-25T20:54:39.833 回答
0

您可能需要检查您的凭据,还需要添加以下语句:

client.Properties.InterfaceVersion = InterfaceVersion.v34;
client.Properties.DefaultEncoding = DataCoding.SMSCDefault;
client.Properties.SourceAddress = "XXXXX";
client.Properties.AddressNpi = NumberingPlanIndicator.Unknown;
client.Properties.AddressTon = TypeOfNumber.Unknown;
client.Properties.SystemType = "XXXX";
client.Properties.DefaultServiceType = ServiceType.DEFAULT;

它将帮助您,并且肯定会删除此异常。如果您发现此答案有用,请标记它。

于 2019-06-18T05:55:43.133 回答