AdhamAwadhi / JamaaSMPP

Jamaa SMPP Client is a .NET implementation of the SMPP protocol that focuses on providing an easy-to-use and robust SMPP client library for .NET developers. This project is intended to be used by developers who want to integrate SMS functionalities in their applications as well as students who are learning the SMPP protocol.
https://github.com/AdhamAwadhi/JamaaSMPP/wiki
Other
45 stars 36 forks source link

Invalid parameter length when setting UserMessageReference #12

Closed mtfash closed 6 years ago

mtfash commented 6 years ago

Whenever I set the UserMessageReference I receive an Invalid Parameter Length exception. It doesn't matter which version of the library I am using or which telecom operator I am connecting to. I have tried this with 3 telecom operators and in all of them I receive this error. I also tried to change the format of the UserMessageReference but It also doesn't make any difference.

Here is the raw capture of the TCP stream of Submit_SM command.

00000010000000150000000000000006
00000010800000150000000000000006
000000430000000400000000000000070001013531320001013933373030323235333735000000000000010008000c54657374204d6573736167650204000431303000
0000001080000004000000c200000007
00000010000000150000000000000008
00000010800000150000000000000008
TextMessage msg = new TextMessage();
msg.DestinationAddress = $"93{subscriber.Number}";
msg.SourceAddress = smppConfig.SourceAddress;
msg.Text = message;
msg.UserMessageReference = sms.ReferenceId;
msg.RegisterDeliveryNotification = true;
client.SendMessage(msg);
AdhamAwadhi commented 6 years ago

I parsed TCP stream captured, I got all of them are OK. Look below (ordered as you wrote) :

as You can see: your user_message_reference is 100

1: EnquireLink -- AllowedSource:Any AllowedSession:Transceiver HasResponse:True Header:EnquireLink Tlv:[] SmppEncodingService:JamaaTech.Smpp.Net.Lib.SmppEncodingService 
2: EnquireLinkResp -- AllowedSource:Any AllowedSession:Transceiver Header:EnquireLinkResp Tlv:[] SmppEncodingService:JamaaTech.Smpp.Net.Lib.SmppEncodingService 
3: SubmitSm -- AllowedSource:ESME AllowedSession:Transmitter ProtocolID:0 PriorityFlag:Level0 ScheduleDeliveryTime: ValidityPeriod: ReplaceIfPresent:False SmDefaultMessageId:0 DestinationAddress:{Address:93700225375, Ton:International, Npi:ISDN} ServiceType: EsmClass:Default RegisteredDelivery:DeliveryReceipt DataCoding:UCS2 SourceAddress:{Address:512, Ton:International, Npi:ISDN} HasResponse:True Header:SubmitSm Tlv:[user_message_reference:100 ] SmppEncodingService:JamaaTech.Smpp.Net.Lib.SmppEncodingService 
4: SubmitSmResp -- AllowedSource:SMSC AllowedSession:Transmitter MessageID: Header:SubmitSmResp Tlv:[] SmppEncodingService:JamaaTech.Smpp.Net.Lib.SmppEncodingService 
5: EnquireLink -- AllowedSource:Any AllowedSession:Transceiver HasResponse:True Header:EnquireLink Tlv:[] SmppEncodingService:JamaaTech.Smpp.Net.Lib.SmppEncodingService 
6: EnquireLinkResp -- AllowedSource:Any AllowedSession:Transceiver Header:EnquireLinkResp Tlv:[] SmppEncodingService:JamaaTech.Smpp.Net.Lib.SmppEncodingService 

Can you give me more details, like

mtfash commented 6 years ago

Thanks Adham for taking the time. The exception that I am getting is this:

An unhandled exception occurred while processing the request.

SmppException: Exception of type 'JamaaTech.Smpp.Net.Lib.SmppException' was thrown.

JamaaTech.Smpp.Net.Client.SmppClient.SendMessage(ShortMessage message, int timeOut) in SmppClient.cs, line 186

Currently I am using the version 1.5.6 of the library. Below screenshots are Wireshark capture of the request and response. The wireshark shows the request as a malformed packet.

capture reqcapture

shridhartpatil commented 6 years ago

private static void client_MessageDelivered(object sender, MessageEventArgs e) { var client = (SmppClient)sender; //Console.WriteLine("SMPP client {0} Message Delivered to: {1}", client.Name, e.ShortMessage.DestinationAddress); Console.WriteLine("SMPP client {0} - Message Delivered: MessageId is : {1},UserMessageReference {2} ",

            client.Name,  e.ShortMessage.ReceiptedMessageId, e.ShortMessage.UserMessageReference);

}

e.ShortMessage.ReceiptedMessageId and e.ShortMessage.UserMessageReference return empty value in MessageDelivered event

while debug I seen PduReceivedEventHander set empty value to this fields

message.ReceiptedMessageId = pdu.GetOptionalParamString(Tag.receipted_message_id); message.UserMessageReference = pdu.GetOptionalParamString(Tag.user_message_reference);

AdhamAwadhi commented 6 years ago

I think this is from Wireshrak, I tried it with my client and I noted that: Wireshrak try to figure another TLV paramater (additional to user_message_reference) and actually there is only one. The process succeeded without any error.

This parameter is partially from user_message_reference, I have no idea why Wireshark behave like that.

smpp_wireshark_usr-msg-ref-full-param smpp_wireshark_usr-msg-ref-figured-param

shridhartpatil commented 6 years ago

Thank you for valuable time. Is there any other idea to store user_message_reference value with message delivery status in Database

AdhamAwadhi commented 6 years ago

Hi @shridhartpatil , you are welcome. This depends on your application. In my case I'm using this: 1 - Save message to DB using EF with state Queued. 2 - Use generated ID from DB to user_message_reference and Send sms. 3 - Update state to Sent when success or DELAY RETRY with Polly. 4 - Update state to Delivered when received client_MessageDelivered

shridhartpatil commented 6 years ago

Yes I need to update state Delivered using user_message_reference but in client_MessageDelivered I get user_message_reference value empty

mtfash commented 6 years ago

Thanks Adham

SM2070 commented 6 years ago

I as well getting same error of 'Invalid parameter length'..I am using Jamaa Library 1.5.3 and using below code for sending SMS ... TextMessage msg = new TextMessage { DestinationAddress = smsDetails.ToMobile, SourceAddress = smppConfig.SourceAddress, Text = smsDetails.Message, RegisterDeliveryNotification = true, //UserMessageReference = smsDetails.RequestId.ToString() }; clientSMPP.SendMessage(msg); Here I commented User MessageReference as Service Provider doesn't support TLV ...When we send few Messages , SMS getting delivered successfully but when we send messages continuously around 10 nos./sec, Service Provider receives below error .... Invalid parameter length:[105] max:[20] safe_value:[ABC FAILURE ALERT(Ge] ' Invalid parameter length:[102] max:[16] safe_value:[ FAILURE ALERT(G]

Kindly let me know what could be reason for this error ...................