2013-08-23 63 views
2

我已經成功實施了使用Jamaa Lib和Jamaa Net的應用程序。感謝開發者。關於Jamaa SMPP異步操作

但我在使用異步發送操作時遇到問題。一個未處理的異常正在不斷提出。如果有人能幫我找出問題,我將非常感激。

請注意。我使用相同的應用程序接收和發送短信。我需要每天發送平均10萬條短信。同時我也收到來自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超時)在 System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage( IntPtr的 MD,對象[]指定參數時,對象服務器,在 System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(即時聊天 味精,IMessageSink replySink)

對象[] & outArgs)在[0]

異常重新拋出:在 System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(消息 reqMsg,布爾bProxyCase)在 System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(對象NOTUSED, MessageData & MSGDATA)在 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)在 System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(即時聊天 味精,IMessageSink replySink)在 System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem。 ThreadPoolCallBack(對象 O)在 System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(對象 狀態)在 System.Threading.ExecutionContext.RunInternal(的ExecutionContext 的ExecutionContext,ContextCallback回調,對象的狀態,布爾 preserveSyncCtx)在 的System.Threading。 ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回調,對象狀態,布爾 preserveSyncCtx)在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在System.Threading.ThreadPoolWorkQueue。調度()在 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

回答

1

您可以嘗試使用Wireshark查看原始數據包,這會給你一個想法什麼錯誤。在我的情況下,這是一個無效的系統ID。