我使用Inetlab.SMPP 2.8.1 (基于许可原因)来实现SMPP网关。短消息与长文本必须分割成小部分。因此,我遵循文章并使用一个MessageComposer实例来组合连接的消息:
private void OnClientSubmitSm(object sender, SmppServerClient client, SubmitSm pdu)
{
_composer.AddMessage(pdu);
if (_composer.IsLastSegment(pdu))
{
string fullMessage = _composer.GetFullMessage(pdu);
// do something
}
}其中_composer是MessageComposer。
但是代码会产生以下错误:
System.ArgumentNullException:值不能为空。(参数'key') 在System.Collections.Concurrent.ConcurrentDictionary
2.ThrowKeyNullException() at System.Collections.Concurrent.ConcurrentDictionary2.TryGetValue(TKey key,TValue& value) 在Inetlab.SMPP.Common.DefaultComposerItemStore.TryGet(String键,ComposerItem& item) 在Inetlab.SMPP.Common.MessageComposer.IsLastSegmentTSmppMessage
注意,类似的代码适用于evDeliverSm事件。但是它不想处理传入的submit_sm PDU。
我做错了什么?我要做什么才能得到预期的结果呢?
发布于 2021-11-08 10:09:06
使用evFullMessageReceived事件解决了这个问题,而不是检查消息段。因此,以下事件处理程序将按预期处理传入的SUBMIT_SM PDU:
// the method handles evClientSubmitSm event of SmppServer instance
private void OnClientSubmitSm(object sender, SmppServerClient client, SubmitSm pdu)
{
try
{
_composer.AddMessage(pdu);
}
catch (Exception error)
{
pdu.Response.Header.Status = CommandStatus.ESME_RSUBMITFAIL;
// log error
}
}
// the method handles evFullMessageReceived event of MessageComposer instance
private void OnFullMessageReceived(object sender, MessageEventHandlerArgs arguments)
{
SubmitSm pdu = null;
SmppClientBase client = null;
try
{
pdu = arguments.GetFirst<SubmitSm>();
client = pdu.Client;
string fullMessage = arguments.Text;
// save message
}
catch (Exception error)
{
pdu.Response.Header.Status = CommandStatus.ESME_RSUBMITFAIL;
// log error
}
}
// the method handles evFullMessageTimeout event of MessageComposer instance
private void OnFullMessageTimeout(object sender, MessageEventHandlerArgs arguments)
{
SubmitSm pdu = arguments.GetFirst<SubmitSm>();
// log warning
}https://stackoverflow.com/questions/69879658
复制相似问题