When I read message from SQL and want to send them via SMPP, I got an error. But when replace parameter with static text, work normally.
Code: Select all
public static ConcurrentQueue<string> iQ;
public static async Task<int> RunTest(SmppClient client)
{
int count = 0;
DataTable dataTable = new DataTable();
try
{
using (SqlConnection sqlConnection = new SqlConnection(@"connection string"))
{
using (SqlCommand sqlCommand = new SqlCommand("sp_getData", sqlConnection))
{
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.AddWithValue("@params1", 1);
sqlCommand.Parameters.AddWithValue("@params2", 1000);
sqlConnection.Open();
dataTable.Load(sqlCommand.ExecuteReader());
}
}
count = dataTable.Rows.Count;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
Stopwatch watch = Stopwatch.StartNew();
foreach (DataRow dtRow in dataTable.Rows)
{
await SubmitSingleMessage(dtRow["From"].ToString(), dtRow["To"].ToString(), dtRow["[Text"].ToString(), client, int.Parse(dtRow["ID"].ToString()));
}
watch.Stop();
return mps = Convert.ToInt32(count / watch.Elapsed.TotalSeconds);
}
private static async Task SubmitSingleMessage(string from, string to, string text, SmppClient client, int messageID)
{
ISubmitSmBuilder builder = SMS.ForSubmit()
.From(from)
.To(to)
.Coding((DataCodings)Enum.Parse(typeof(DataCodings), text))
.Text(text);
try
{
IList<SubmitSmResp> resp = await client.SubmitAsync(builder);
if (resp.All(x => x.Header.Status == CommandStatus.ESME_ROK))
{
var returns = string.Join(",", resp.Select(x => x.MessageId));
using (var output = new StringWriter())
{
JSON.Serialize(
new
{
messageID = messageID,
returnIds = returns.Split(',').Select(int.Parse).ToList(),
totalPart = returns.Split(',').Select(int.Parse).ToList().Count
},
output
);
iQ.Enqueue(output.ToString());
}
}
}
catch (Exception ex)
{
//_log.Error("Submit failed. Error: {0}", ex.Message);
}
}
}
public class resultSMS
{
[JilDirective(Name = "messageID", IsUnion = true)]
public int messageID { get; set; }
[JilDirective(Name = "returnIds", IsUnion = true)]
public List<int> returnIds { get; set; }
[JilDirective(Name = "totalPart", IsUnion = true)]
public int totalPart { get; set; }
}