关于Jamaa SMPP异步操作

时间:2013-08-23 14:56:52

标签: c# smpp

我使用Jamaa Lib和Jamaa Net成功实施了一个应用程序。感谢开发人员。

但是当我使用异步发送操作时,我遇到了问题。正在不断提出未处理的异常。如果有人能帮助我找出问题,我将不胜感激。

请注意。我正在使用相同的应用程序接收和发送短信。我需要每天平均发送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)   消息,Int32 timeOut)at   System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr的   md,Object [] args,Object server,Object []&amp; outArgs)at   System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(即时聊天   msg,IMessageSink replySink)

     

在[0]处重新抛出异常:at   System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(消息   reqMsg,Boolean bProxyCase)at   System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed,   MessageData&安培; msgData)at   JamaaTech.Smpp.Net.Client.SendMessageCallBack.EndInvoke(IAsyncResult的   结果)在   JamaaTech.Smpp.Net.Client.SmppClient.EndSendMessage(IAsyncResult的   结果)在   Transciever.Program.SendMessageCompleteCallback(IAsyncResult结果)   在   d:\ SMPP \ transciever \ appTranscieverinCSharp \ appTranscieverinCSharp \ Program.cs中:线   223点   System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(即时聊天   msg)at   System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(即时聊天   msg,IMessageSink replySink)at   System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(对象   o)at   System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(对象   国家)   System.Threading.ExecutionContext.RunInternal(执行上下文   executionContext,ContextCallback回调,对象状态,布尔值   preserveSyncCtx)at   System.Threading.ExecutionContext.Run(执行上下文   executionContext,ContextCallback回调,对象状态,布尔值   preserveSyncCtx)at   System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()   在System.Threading.ThreadPoolWorkQueue.Dispatch()at   System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分: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;

它将帮助您,并且一定会消除此异常。 如果您认为此答案有用,请标记它。